来自其他应用程序的 React Native 深度链接
React Native deep linking from other app
我们的应用程序应该可以在 company://upload 上找到。我创建了 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>
正在打开应用程序,但在 react-native 中我无法捕捉到 url。我的实施:
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();
}
}
- 实现在
router.js
中,这是第一个 React 组件。
- 意图过滤器在 .MainActivity
- 当我在另一个应用程序上单击该应用程序时,它正在打开它,因此链接的 java 部分正在运行。
版本:
"react-native": "0.42.0",
Android SDK 23
我写了一个测试深层链接的脚本:
adb shell am start -W -a android.intent.action.VIEW -d "company://" com.companyapps/.MainActivity
深层链接是正确的,问题出在我的应用程序的 Java 部分。
我们的应用程序应该可以在 company://upload 上找到。我创建了 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>
正在打开应用程序,但在 react-native 中我无法捕捉到 url。我的实施:
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();
}
}
- 实现在
router.js
中,这是第一个 React 组件。 - 意图过滤器在 .MainActivity
- 当我在另一个应用程序上单击该应用程序时,它正在打开它,因此链接的 java 部分正在运行。
版本:
"react-native": "0.42.0",
Android SDK 23
我写了一个测试深层链接的脚本:
adb shell am start -W -a android.intent.action.VIEW -d "company://" com.companyapps/.MainActivity
深层链接是正确的,问题出在我的应用程序的 Java 部分。