shi*_*zou 1 android deep-linking react-native
我试图让一个 url 打开应用程序,并将一些数据与这个 url 传递到应用程序中,但它不起作用。
我在 AndroidManifest.xml 中的活动标签:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"> <-- added this
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="fcm.ACTION.HELLO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-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="conv"
android:host="convid"/> <-- so urls of the form 'conv://convid/ will open the app
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我添加到应用程序的入口类:
componentDidMount() {
Linking.addEventListener('url', (e) => {
console.log("url", e);
});
Linking.getInitialURL().then((url) => {
if (url) {
console.log('Initial url is: ' + url);
}
})
}
Run Code Online (Sandbox Code Playgroud)
但是当我打开浏览器并转到conv://convid任何内容时都没有记录并且应用程序没有打开。
当然,我在浏览器之前打开了我的应用程序。
如果将链接输入到浏览器的地址栏中,应用程序将不会打开。它必须是一个网页<a/>标签,如:
<a href="http://example.com"></a>
某些页面内的链接。( https://developer.chrome.com/multidevice/android/intents )
由于您可能没有将标签放入其中的网页,因此对于您的测试,您可以使用 adb 命令。打开控制台并写入以下行:
adb shell am start -W -a android.intent.action.VIEW -d "YOURHOST://YOURSCEME/" com.YOURAPPNAME
Run Code Online (Sandbox Code Playgroud)
例如,在您的情况下,它应该类似于(使用您的应用程序名称更改 YOURAPPNAME):
adb shell am start -W -a android.intent.action.VIEW -d "convid://conv/" com.YOURAPPNAME
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 Windows,并且如果它说 adb 命令未定义,则您需要从 SDK 文件夹中的 platform-toolsfolder 运行该命令,例如:
Android/Sdk/platform-tools/
| 归档时间: |
|
| 查看次数: |
2926 次 |
| 最近记录: |