简体   繁体   中英

React Native deep linking from other app

There is the our application which should be available on company://upload. I created the 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. 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.
  • The intent-filter is in the .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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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