Android deeplink用来从网页中自家网站直接打开自家APP,在微信各种封杀情况下,一般需要在浏览器中通过deeplink方式打开APP
实现上,通过声明导出activity组件,及相关intent-filter,如下
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hwid"/>
<data android:host="startup"/>
</intent-filter>
网站上通过如下代码即可打开APP
<a href="hwid://com.huawei.hwid" target="_blank" rel="external nofollow" >hwid</a>
若恶意APP注册相同的组件和intent-filter,则浏览器会提示用户自行选择,这里就存在被劫持风险,导致用户选择了恶意APP
Android存在机制可从浏览器直接打开目标APP,而不需要用户选择的过程
android:autoVerify="true"
除了activity组件的intent-filter配置该属性,还需要在"host"上增加供查询文件(host为intent-filter中的配置)
https://host/.well-known/assetlinks.json
注意,仅支持https协议
assetlinks.json中需要包含sha256_cert_fingerprints和package_name
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.example", "sha256_cert_fingerprints": ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"] } }]
这样,APP在安装时就将对应的路由写入配置(adb shell dumpsys package d 可以验证),用户也就不会看到选择弹框
验证assetlinks.json格式 https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://domain.name:optional_port&relation=delegate_permission/common.handle_all_urls
参考 https://developer.android.com/training/app-links/verify-site-associations