[英]Deep linking react native app on Android
我试图让一个网址打开应用程序,并将这个网址的一些数据传递到应用程序,但它不起作用。
我在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>
我添加到应用程序的入门级:
componentDidMount() {
Linking.addEventListener('url', (e) => {
console.log("url", e);
});
Linking.getInitialURL().then((url) => {
if (url) {
console.log('Initial url is: ' + url);
}
})
}
但是当我打开浏览器并转到conv://convid
没有记录任何内容并且应用程序无法打开。
当然我在浏览器之前打开了我的应用程序。
如果链接已输入浏览器的地址栏,则该应用程序将无法打开。 它必须是一个网页<a/>
tag like:
<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
例如,在你的情况下它应该是这样的(用你的应用程序的名称更改YOURAPPNAME):
adb shell am start -W -a android.intent.action.VIEW -d "convid://conv/" com.YOURAPPNAME
如果您正在使用Windows,并且如果它说未定义adb命令,则需要从SDK文件夹中的platform-tools文件夹运行命令,例如:
Android/Sdk/platform-tools/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.