简体   繁体   English

android:React native 从另一个应用程序打开一个应用程序?

[英]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 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示例

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.

相关问题 在本机反应中打开 Android 手机上已安装的应用程序 - Open installed app on android phone in react native 如何从另一个 React 应用打开一个 React 应用 - How to open a React app from another React app 从 React Native App 打开外部应用程序(按钮单击) - Open external App from React native App ( Button Click) React Native Expo - 单击链接时从 android 浏览器打开我的应用程序 - React Native Expo - Open my app from android browser when clicking a link 从集成到现有 Android 应用程序中的 React Native 应用程序获取结果 - Get a result from a react native app integrated into an existing android app React Native不从父应用程序调用Android Native方法 - React native not calling Android native method from parent app 从本机iOS应用程序打开另一个应用程序 - Opening another app from react-native iOS application 从 React-Native 应用程序中的另一个类访问静态变量? - Access static variable from another class in React-Native app? 如何在Android的React Native中以编程方式打开Tez应用(印度的Google Pay应用)? - How can I open Tez app (Google Pay app in India) programmatically in React Native in Android? React-Native:如何从反应原生应用程序打开谷歌游戏商店? - React-Native: How to open google play store from react native app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM