我在 AndroidManifest.xml
中定义我的应用链接如下:
<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="mysite.com" android:scheme="http"/>
<data android:host="mysite.com" android:scheme="https"/>
<data android:host="www.mysite.com" android:scheme="http"/>
<data android:host="www.mysite.com" android:scheme="https"/>
</intent-filter>
该应用程序正确检测来自主机的 URL,但会提示用户是否要在应用程序或浏览器中打开它们,因为验证失败,如 Android 监视器控制台所示:
01-17 15:44:28.847 7084-30015/? I/IntentFilterIntentSvc: Verifying IntentFilter. verificationId:2 scheme:"https" hosts:"mysite.com www.mysite.com" package:"com.site.myapp.android.flavor".
01-17 15:44:29.821 7084-30015/? I/IntentFilterIntentSvc: Verification 2 complete. Success:false. Failed hosts:mysite.com,www.mysite.com.
我的 assetlinks.json 文件位于 mysite.com/.well-known/assetlinks.json
并包含正确的包名称和 SHA256 哈希。它也可以通过 http 和 https 访问。我已经通过从 APK 中提取 CERT.RSA 文件并使用 keytool -printcert -file CERT.RSA
我尝试调用 https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://domain1:port&relation=delegate_permission/common.handle_all_urls
作为以及使用 google site Statement List Tester并且都返回 OK。
我正在使用运行 Android 7 的 Nexus 设备进行测试。
根据 the documentation我已经完成了应用程序链接工作所需的一切。还有什么我可以检查的吗?
我的服务器在 Windows 7 上运行 IIS,我已经在 IIS 和 web.config 文件中添加了 application/json 作为 mimetype。会不会因为我使用的是自签名 SSL 证书而失败?
编辑:SingleHostAsyncVerifier 还记录验证失败。 (将 mysite 替换为示例和 SHA 哈希)
01-17 15:44:29.817 7084-30017/? I/SingleHostAsyncVerifier: Verification result: checking for a statement with source a <
a: "https://www.example.com"
>
, relation delegate_permission/common.handle_all_urls, and target b <
a: "com.mypackage.flavor"
b <
a: "(SHA256 hash)"
>
>
--> false.
01-17 15:44:29.820 7084-30016/? I/SingleHostAsyncVerifier: Verification result: checking for a statement with source a <
a: "https://example.com"
>
, relation delegate_permission/common.handle_all_urls, and target b <
a: "com.mypackage.flavor"
b <
a: "(SHA256 hash)"
>
>
--> false.
最佳答案
尽管应用链接文档中未提及,但应用链接要求服务器具有来自公共(public)或可信证书颁发机构的有效 SSL 证书。自签名证书不起作用。
切换到 https://www.thawte.com/ 颁发的 SSL 证书后应用程序链接验证成功完成。
关于Android M 应用链接验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41708549/