【问题标题】:(react-native-deep-link) Triggering app using incoming link issue (playstore url)(react-native-deep-link)使用传入链接问题触发应用程序(playstore url)
【发布时间】:2019-03-25 13:49:19
【问题描述】:

我构建了一个 API,它重定向到 playstore 中的相应应用链接。在互联网浏览器中使用 API 时,它不是打开应用程序,而是打开网页。

我正在使用以下代码:

AndroidManifest.xml

<intent-filter android:label="filter_react_native">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT"/>
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:host="scoutnex-deeplink.herokuapp.com" android:scheme="https" android:pathPrefix="/scoutnex"/>
</intent-filter>

App.js

componentDidMount(){
   Linking.getInitialURL()
      .then(url => this.handleOpenURL({ url }))
      .catch(console.error);
   Linking.addEventListener("url", this.handleOpenURL);
}

如果我使用类似下面的代码,互联网浏览器会提示请求打开一个使用 url peopleapp://people 的外部应用程序。

<data android:host="people" android:scheme="peopleapp"/>

【问题讨论】:

    标签: android react-native react-native-android deep-linking


    【解决方案1】:
    > <intent-filter android:label="filter_react_native">
    >           <action android:name="android.intent.action.VIEW" />
    >           <category android:name="android.intent.category.DEFAULT"/>
    >           <category android:name="android.intent.category.BROWSABLE" />
    >           <data android:host="scoutnex-deeplink.herokuapp.com" android:scheme="https" android:pathPrefix="/scoutnex"/>
    >     </intent-filter>
    

    生成的uri将是https://scoutnex-deeplink.herokuapp.com/scoutnex

    低于数据意图

    > <data android:host="people" android:scheme="peopleapp"/>
    

    生成的 uri 将是 peopleapp://people

    请检查您是否正在使用路由器,如果是,那么您应该在堆栈导航器中设置人员屏幕。

    终于,

    测试您的意图数据 uri 的最佳方法是:

    1) 如果尚未完成,请卸载现有应用程序。

    2) 再次同步并构建代码。

    3) 使用 uri peopleapp://people 在您的应用中调用 webview。

    4) 它应该可以工作。

    5) 如果您使用的是模拟器,请查看 android here 提供的以下链接

    6) 在终端中运行此程序(尝试 adb devices 进行测试)。

    > $ adb shell am start
    >         -W -a android.intent.action.VIEW
    >         -d <URI> <PACKAGE>
    

    7) URI 将是 peopleapp://people

    8) PACKAGE 将是您的包/应用程序/名称,即..@string/app_name

    希望这对您有所帮助。我希望您的代码块更加清晰。因此,如果您发现它令人困惑,请发表评论。

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      • 2022-12-28
      • 2020-03-07
      • 2016-07-14
      相关资源
      最近更新 更多