简体   繁体   English

从其他应用程序React Native深层链接

[英]React Native deep linking from other app

There is the our application which should be available on company://upload. 我们的应用程序应该在company:// upload上提供。 I created the itent-filter: 我创建了itent-filter:

<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="company"
    android:host="upload" />
</intent-filter>

It is opening the application, but inside the react-native I couldn't catch the url. 它正在打开应用程序,但在反应本机内部我无法捕获该URL。 My implementation: 我的实施:

componentWillMount() {
  Linking
    .getInitialURL()
    .then(event => this.handleOpenURL(event))
    .catch(console.error);
  Linking.addEventListener('url', this.handleOpenURL);
  this.props.loadCredentials();
}

handleOpenURL(event) {
  console.log(event);
  switch (event.url) {
    case `${Config.APP_SCHEMA}upload`:
      Actions.Upload();
      break;
    default:
      Actions.Home();
  }
}
  • The implementation is in the router.js and this is the first React component. 实现在router.js ,这是第一个React组件。
  • The intent-filter is in the .MainActivity intent-filter位于.MainActivity中
  • When I click on the application on the other application it is opening it up, so the java part of the linking is working. 当我点击另一个应用程序上的应用程序时,它正在打开它,因此链接的java部分正在工作。

Versions: 版本:

  • "react-native": "0.42.0",
  • Android SDK 23

I wrote a script for testing the deep-linking: 我写了一个用于测试深层链接的脚本:

adb shell am start -W -a android.intent.action.VIEW -d "company://$1" com.companyapps/.MainActivity

The deep-linking is right, the problem was with the Java part of my application. 深层链接是正确的,问题在于我的应用程序的Java部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM