【问题标题】:How can I open Tez app (Google Pay app in India) programmatically in React Native in Android?如何在 Android 的 React Native 中以编程方式打开 Tez 应用(印度的 Google Pay 应用)?
【发布时间】:2018-10-24 07:09:03
【问题描述】:

Tez 是印度一种流行的支付方式。

 tezFunc()
      {

        const url = 'com.google.android.apps.nbu.paisa.user://';
          Platform.OS === 'android' ? 

   Linking.canOpenURL(url).then(supported => {
    if (!supported) {

        Linking.openURL('https://play.google.com/store/apps/details?id=com.google.android.apps.nbu.paisa.user&hl=en_IN')
    }else {
      return Linking.openURL(url);
}

 }).catch(err => console.error('An error occurred', err))
 :
          Linking.openURL('https://itunes.apple.com/in/app/google-pay-for-india-tez/id1193357041?mt=8')
        }

在这里,我将应用程序的捆绑包 ID 作为 url 传递。这种方式每次打开 Play 商店时,我都不知道如何实现。如果设备中存在该应用,我想打开它,否则打​​开 Play 商店链接。

但是,对于 WhatsApp,我已经实现了这一点,但对于 Tez,它不起作用。

这在 WhatsApp 工作的情况下

_whatsaap = () =>
{
  const url = 'whatsapp://send?text=. I have an enquiry, please reply me ASAP!&phone=**********';
  Linking.canOpenURL(url).then(supported => {
   if (!supported) {
    Alert.alert(
      'Comet Graphic',
      'Sorry, The app is not installed in your device! Press OK to install it now!',
      [{
        text: 'OK', onPress: () =>Linking.openURL(' https://play.google.com/store/apps/details?id=com.whatsapp') },
        {text: 'Cancel'},
       ], {
        cancelable: false
      }
    )

如何在 Tez 中实现这一点?

【问题讨论】:

    标签: javascript reactjs react-native expo google-pay


    【解决方案1】:

    我创建了一个 npm 包,使 ReactNative 开发人员能够在移动应用程序上接受付款。

    https://www.npmjs.com/package/react-native-google-pay-tez

    试试这个。

    注意:Google 仅支持通过已安装的 Google Pay 应用程序接受付款的 Android Intent。对于 iOS,您必须使用全渠道,您必须联系他们。

    【讨论】:

      【解决方案2】:

      我找到了以下模块:https://www.npmjs.com/package/react-native-send-intent#example--check-if-an-application-is-installed

      我认为您可以尝试以下方法:

      1. 检查应用程序是否安装在用户设备上,使用: SendIntentAndroid.isAppInstalled('com.google.android.gm').then((isInstalled) => {});

      2. 如果安装运行:

        SendIntentAndroid.openApp('com.google.android.gm').then((wasOpened) => {});

        如果您想传递其他参数,请使用:

        SendIntentAndroid.openApp('com.mycorp.myapp', {"com.mycorp.myapp.reason": "just because", "com.mycorp.myapp.data": "必须是字符串"})。然后((wasOpened) => {});

      我不确定这是如何工作的,但据我所知,您可以直接使用以下方式安装 apk:

      SendIntentAndroid.installRemoteApp('https://example.com/my-app.apk', 'my-saved-app.apk').then((installWasStarted) => {});

      更新: 请试试这个示例代码:

      _tez = () => {
      SendIntentAndroid.isAppInstalled('com.tez.blablabla').then((isInstalled) => {
          if (isInstalled) {
              SendIntentAndroid.openApp('com.google.android.gm').then((wasOpened) => {
                  if (wasOpened) {
                      console.log("App opened");
                  }
                  else {
                      console.log("Error opening app or it was not opened");
                  }
              });
          }
      });}
      

      【讨论】:

      • 感谢您的回答,但请您说得更具体些吗?
      • 以我不知道如何使用意图和所有东西的方式更具体。我是 RN 和开发线的新手。如果你能帮我写代码会很有帮助
      • 我在答案中添加了您需要的代码片段。你可以只使用这些。只需按照上述步骤并替换应用程序包 ID。您不需要详细了解意图是什么。您基本上向您希望打开应用程序或执行操作的 android 系统发送一个意图,操作系统会为您处理它。我更新了答案并粘贴了一些示例代码检查一下
      • 非常感谢兄弟...我一定会更新它是否有效。但是感谢您的宝贵时间.. 打算试试这个。
      • 错误:未定义不是评估“RNSendIntentAndroid.isAppInstalled(packagename)”的函数
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-08
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      • 2018-10-10
      相关资源
      最近更新 更多