[英]android: React native open an app from another app?
I am trying to open a another app( https://play.google.com/store/apps/details?id=com.inova.velocity ) from my app.我正在尝试从我的应用程序中打开另一个应用程序( https://play.google.com/store/apps/details?id=com.inova.velocity )。 But there are all the tutorial just redirecting url to playstore only.(I found a github link( https://github.com/FiberJW/react-native-app-link ) and it opens the app for iOS only, but for Android it is redirecting to playstore).
但是所有的教程都只是将 url 重定向到 playstore。(我找到了一个 github 链接( https://github.com/FiberJW/react-native-app-link )它只打开了 iOS 的应用程序,但适用于 Android它正在重定向到 Playstore)。 Is there is any way to solve this problem?
有没有办法解决这个问题?
Linking.canOpenURL('market://details?id=com.inova.velocity')
.then((canOpen) => {
if (canOpen) {
console.log('open app');
return Linking.openURL('market://details?id=com.inova.velocity')
};
}).catch(err => console.log('An error occurred', err));
Yes your code is correct.是的,您的代码是正确的。 But you have used playstore url, instead of schema url.
但是您使用了 playstore url,而不是 schema url。 you have to set the schemaUrl which you can get it from relevant app developer.
您必须设置可以从相关应用程序开发人员处获取的 schemaUrl。 if there is no schema url set for the that app you can't open it.
如果没有为该应用程序设置架构 URL,您将无法打开它。 after you get the SchemaUrl you can use your code.
获得 SchemaUrl 后,您可以使用您的代码。 like below.
像下面。
Linking.canOpenURL(SchemaUrl).then(supported => {
if (supported) {
console.log('accepted');
return Linking.openURL(SchemaUrl);
} else {
console.log('an error occured');
}
}).catch(
err => console.log('an error occured');
);
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示例
using react-native-send-intent module , you can do使用react-native-send-intent 模块,你可以做到
SendIntentAndroid.openApp('packagename').then((wasOpened) => {}); SendIntentAndroid.openApp('packagename').then((wasOpened) => {}); where your package name is whatever application package name you want to open.
您的包名称是您要打开的任何应用程序包名称。
for eg SendIntentAndroid.openApp('com.inova.velocity').then((wasOpened) => {});例如 SendIntentAndroid.openApp('com.inova.velocity').then((wasOpened) => {});
wasOpened is a Boolean promise telling you whether the app was opened or not wasOpened 是一个布尔承诺,告诉您应用程序是否已打开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.