[英]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 changepacakage name
inSendIntentAndroid.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.