Intent Filter with android:autoVerify=quot;truequot; - never verified at installation, default app links don#39;t work(使用Android的意图过滤器:AutoVerify=;TrueQuot;-安装时从未验证,默认应用程序链接不起作用)
问题描述
我正在我的Android应用程序中使用Branch.io SDK,并希望使我的应用程序成为Android 6上分支链接的默认处理程序,here(Android指南)和here(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>
但是,当我在设备上安装内部版本时,当我单击具有正确主机和路径的链接时,仍然会看到选择器对话框。在阅读了extensive guide on app linking之后,我相信这是因为我的设备从未验证我的应用程序的意图过滤器。例如,当我从Play Store安装Twitter应用程序时,我在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:.
但我在安装应用程序时没有看到这样的消息。我尝试了发布和调试版本,尝试将其上传到Play商店中的Alpha测试,并从那里安装,结果相同。为什么Android不验证我的意图过滤器?
推荐答案
已通过将此数据标记移动到单独的意图筛选器修复此问题:
<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的消息现在按预期显示在日志中。
这篇关于使用Android的意图过滤器:AutoVerify=&;True&Quot;-安装时从未验证,默认应用程序链接不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!