我正在处理构建变体,并希望根据变体捕获其他链接。我希望所有变体都从主机 1 捕获链接,所以我在我的主 AndroidManifest.xml
文件中声明了一个 intent-filter
,如下所示:
<activity android:name=".activity.DeepLinkActivity"
android:noHistory="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:host="hostOne.com" android:path="/page.aspx" android:scheme="http"/>
</intent-filter>
</activity>
我还为其他变体生成部分 list ,例如 hostTwo.com,如下所示:
<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain">
<application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile">
<activity android:name=".activity.DeepLinkActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http://" android:host="hostTwo.com" android:path="/page.aspx"/>
</intent-filter>
</activity>
</application>
</manifest>
它根据构建变体放置在一个适当命名的文件夹中 (based upon the documentation here) Android Studio 的合并 list View 显示主机二的 intent-filter
已添加到最终合并的 list 中,但是,模拟器或实际设备无法捕获为第二个主机准备的 Intent 。
我正在命令提示符中生成这样的 Intent :
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hostone.com/page.aspx"
它适用于 hostone,但正在做
adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "http://hosttwo.com/page.aspx"
将启动浏览器,因为应用无法捕获它。
Android 应用程序链接是否仅适用于一个主机名?还有什么我可以尝试的吗?
最佳答案
我发现部分 list 不正确。在intent-filter
的 data
标签,android:scheme="http://"
由于尾随 ://
而无效.
根据 google's documentation , Android 构建 intent-filter
URI 像这样:<scheme>://<host>:<port>/<path>
所以在声明中包含它是不必要的。
将我的声明更改为 android:scheme="http"
之后合并继续成功,操作系统尝试验证部分 list 中定义的链接!
更正了部分 list :
<?xml version="1.0" encoding="UTF-8"?><manifest package="com.package.my.domain">
<application xmlns:android="http://schemas.android.com/apk/res/android" android:name="AlarmMobile">
<activity android:name=".activity.DeepLinkActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http" android:host="hostTwo.com" android:path="/page.aspx"/>
</intent-filter>
</activity>
</application>
</manifest>
关于Android 应用程序链接多个 Intent 过滤器主机和 list 合并不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42348145/