简体   繁体   English

从 React Native App 打开外部应用程序(按钮单击)

[英]Open external App from React native App ( Button Click)

I want to open New React native App by clicking on Button in which I have used我想通过单击我使用过的按钮来打开 New React Native App

Linking Concepts in React native在 React Native 中链接概念

React native Code : Test is the name of the Other App React native Code:Test 是其他应用程序的名称

Linking.openURL('Test://app');

Also following URL for adding Intent in the android.manifest.xml file Andriod Intent还遵循在 android.manifest.xml 文件中添加 Intent 的 URL Andriod Intent

Code : Android.manifestfile.xml代码:Android.manifestfile.xml

  <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <category android:name="com.Test" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data android:scheme="Test" android:host="app" />
          </intent-filter>
      </activity>

How can I resolve the issue?我该如何解决这个问题?

Add this code in your AndroidManifest.xml file parallel to current intent filter将此代码添加到与当前意图过滤器平行的 AndroidManifest.xml 文件中

 <intent-filter android:label="@string/app_name">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "example://gizmos” -->
        <data android:scheme="app"
              android:host="testApp" />
    </intent-filter> 

and run this command React-native run-android并运行此命令React-native run-android

Add below code to your react-native file.将以下代码添加到您的 react-native 文件中。

<Button title="Click me" onPress={ ()=>{ Linking.openURL('app://testApp')}} />

for save the time .为了节省时间。 You can to both code in same application and same application will be open on button press您可以在同一个应用程序中同时编写代码,并且在按下按钮时将打开同一个应用程序

i just try this code and its working for me let me know if still facing issue (Y)我只是试试这个代码,它对我有用让我知道是否仍然面临问题(Y)

You can open the external application by using following code您可以使用以下代码打开外部应用程序

Linking.canOpenURL("fb://app").then(supported => {
  if (supported) {
    Linking.openURL("fb://app");
  } else {
    alert('sorry invalid url')
  }
});

100% working for open all app from another app using react-native-send-intent . 100%使用react-native-send-intent从另一个应用程序打开所有应用程序。

React Native Android module to use Android's Intent actions for opening third party apps. React Native Android模块使用Android的Intent操作打开第三方应用程序。

Installation npm install react-native-send-intent --save 安装npm install react-native-send-intent --save

Register Module >= 0.29 (in MainApplication.java) Adding only 2 lines 注册模块> = 0.29(在MainApplication.java中)仅添加2行

import com.burnweb.rnsendintent.RNSendIntentPackage;  // <--- import in MainApllication.java

public class MainApplication extends Application implements ReactApplication {
  ......

  @Override
  protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RNSendIntentPackage()); // <------ add this line to your MainApplication 
  class
  }

  ......

  }

Example / Open App in your react-native code 示例/在您的本机代码中打开应用

 SendIntentAndroid.isAppInstalled('com.medlife.customer').then((isInstalled) => {
            if (isInstalled) {
                SendIntentAndroid.openApp('com.medlife.customer').then((wasOpened) => {
                });
                console.log("is installed true");
            }
            else {
                Linking.openURL('https://play.google.com/store/apps/details?id=com.medlife.customer&hl=en').catch(err => {
                    console.log(err)
                })
            }
        });

I am opening 3rd party Medlife app from my app if you have need to open another app then only change pacakage name in SendIntentAndroid.openApp('com.medlife.customer') 如果您需要打开另一个应用程序,那么我将从我的应用程序中打开3rd Party Medlife应用程序,然后仅在SendIntentAndroid.openApp('com.medlife.customer')更改pacakage name

react-native-send-intent git hub example here 在这里反应本地发送意图git hub示例

<Button title="Click me" onPress={ ()=>{ Linking.openURL('https://google.com')}} />

这是您可以查看的链接: https : //snack.expo.io/rJm_YkqyW

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cordova-通过单击按钮打开本机电子邮件应用程序 - Cordova - Open native email app from button click 如何在IOS中从我的React-Native应用程序打开外部应用程序? - How can I open a external App from my React-Native App in IOS? android:React native 从另一个应用程序打开一个应用程序? - android: React native open an app from another app? 如何在React Native中单击按钮以打开React Native模式? - How to open a react native modal on button click in react native? 如何使用 react-native-firebase/messaging(FCM) 从栏点击通知后将应用程序打开到特定页面? - How to open app to specific page after click notification from bar by using react-native-firebase/messaging(FCM)? 如何在我的React应用程序中打开外部网站 - How to open external website in my React app 从浏览器表单提交按钮重定向到应用程序本机响应 - Redirect from browser form submit button to app react native React-Native:如何从反应原生应用程序打开谷歌游戏商店? - React-Native: How to open google play store from react native app? 如何使用特定于 url 的 React Native 打开应用程序 - How to open app with an url specific react native 如何使用本机打开日历应用 - How to open calendar app with react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM