【问题标题】:React-Native: How to open google play store from react native app?React-Native:如何从 React Native 应用程序打开 google play 商店?
【发布时间】:2017-03-08 19:19:51
【问题描述】:

当用户按下 react-native 应用程序内的按钮时,我正在尝试找到一种方法如何使用我的应用程序打开 google play 商店。有没有办法做到这一点?

【问题讨论】:

标签: javascript android reactjs react-native


【解决方案1】:

如果人们懒得通读 android 令人讨厌的 SPA 开发文档:

market://details?id=<package_name>

在 react-native 领域:

Linking.openURL("market://details?id=<package_name>");

例子:

Linking.openURL("market://details?id=googoo.android.btgps");

编辑: 确保导入Linking 以使用它

import { View, Text, StyleSheet, Linking } from 'react-native';

【讨论】:

  • 我收到"Could not open URL 'market://detail?id=': No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://detail?id= flg=0x10000000 }" 错误。
  • 您是在物理设备上还是在模拟器中测试?
  • 我找不到变量链接
  • 它包含在 RN API 中必须将它与您的其他东西一起导入:import { View, Text, StyleSheet, Linking } from 'react-native';
【解决方案2】:

您可以使用深度链接将您的用户从您的应用中重定向,方法是: https://developer.android.com/distribute/tools/promote/linking.html

还有来自 react-native 的 Linking API: http://facebook.github.io/react-native/docs/linking.html

【讨论】:

    【解决方案3】:

    对于未来的用户,您可以继续阅读已接受答案中的文档以获取更多信息。但是,如果您想要更快的结果,这里就是。

    使用来自react-nativeLinking作为

    import { Linking } from 'react-native'
    
    Linking.openURL("http://play.google.com/store/apps/details?id=<package_name>")
    

    如果您使用的是 expo,那么下面的代码适合您。

    通过expo install expo-linking安装expo-linking

    import * as Linking from "expo-linking";
    
    Linking.openURL("http://play.google.com/store/apps/details?id=<package_name>")
    

    注意:&lt;package_name&gt; 是您在清单文件中定义的应用程序包名称,如果您使用的是 expo,则为 app.json

    【讨论】:

      猜你喜欢
      • 2018-11-24
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多