我在 Android 应用程序中使用branch.io SDK,并希望使我的应用程序成为 Android 6 上分支链接的默认处理程序,如下所述here http://developer.android.com/training/app-links/index.html(Android 指南)和here https://dev.branch.io/getting-started/universal-app-links/guide/android/(Branch.io 指南)
这是我的活动在 AndroidManifest.xml 中的声明:
<activity android:name="com.mypackage.MyActivity"
android:launchMode="singleTask">
<intent-filter tools:node="merge" android:autoVerify="true">
<data android:scheme="@string/url_scheme" android:host="open"/>
<data android:scheme="https"
android:host="@string/branch_io_host"
android:pathPrefix="@string/branch_io_path_prefix"/>
<data android:scheme="http"
android:host="@string/branch_io_host"
android:pathPrefix="@string/branch_io_path_prefix"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
但是,当我在设备上安装版本时,当我单击具有正确主机和路径的链接时,我仍然会看到选择器对话框。读完本文后有关应用程序链接的详细指南 https://chris.orr.me.uk/android-app-linking-how-it-works/,我相信发生这种情况是因为我的设备从未验证我的应用程序的意图过滤器。例如。当我安装一个Twitter从 Play 商店下载应用程序后,我在 LogCat 中看到以下消息:
03-24 15:04:27.231: D/IntentFilterVerificationReceiver(16965): Received ACTION_INTENT_FILTER_NEEDS_VERIFICATION.
03-24 15:04:27.248: I/IntentFilterIntentService(16965): Verifying IntentFilter. verificationId:2 scheme:"https" hosts:"twitter.com www.twitter.com ads.twitter.com" package:"com.twitter.android".
03-24 15:04:30.134: I/IntentFilterIntentService(16965): Verification 2 complete. Success:true. Failed hosts:.
但当我安装应用程序时,我没有看到这样的消息。我尝试了发布和调试版本,尝试将其上传到游戏商店中的 Alpha 测试并从那里安装,结果相同。为什么 Android 不验证我的 Intent 过滤器?
通过将此数据标记移动到单独的意图过滤器中来修复此问题:
<data android:scheme="@string/url_scheme" android:host="open"/>
这就是 AndroidManifest 现在的样子:
<activity android:name="com.mypackage.MyActivity"
android:launchMode="singleTask">
<intent-filter tools:node="merge" android:autoVerify="true">
<data android:scheme="https"
android:host="@string/branch_io_host"
android:pathPrefix="@string/branch_io_path_prefix"/>
<data android:scheme="http"
android:host="@string/branch_io_host"
android:pathPrefix="@string/branch_io_path_prefix"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
<intent-filter>
<data android:scheme="@string/url_scheme" android:host="open"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
来自 IntentFilter 的消息现在按预期显示在日志中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)