1.Android Intent 系统 (意图)
你应该知道的简单的intent
startActivity()
startActivityForResult()
startService()
sendBroadcast()
下图Android Intent系统 startActivity() 和onCreate() intents:
Android Intent系统是应用处理内容和请求灵活的机制。
2.创建网站的关联
该声明由主JSON文件,这是专门命名assetlinks.json完成。该文件必须位于特定位置上主域,例如:
JSON文件包含有关Android应用程序,这将是该网站下的URL默认处理程序的信息。在JSON文件,必须具有以下结构:
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.yourapp.androidapp",
"sha256_cert_fingerprints": [""]
}
}]
下面是前面的结构中的某些内容:
PACKAGE_NAME:这是你的应用程序的清单sha256_cert_fingerprints包名称:这是您的应用程序的SHA-256指纹使用下面的命令,如果你没有这个SHA(以下简称安全散列算法):
keytool -list -v -keystore app_release_signing.keystore
3.触发应用链接验证
您可以在assetlinks.json文件中声明的任何应用程序的链接要求自动验证。autoVerify属性每个意图过滤在清单中,它设置为true:请求验证是通过添加android:autoVerify完成。
比方说,我们拥有一个Newton的应用程序和域。我们希望autoverify具有android.intent.action.VIEW操作的意图过滤器。
以下是从Newton的处理程序环节和autoverification属性的示例活动:
<activity android:name="com.newton.XXX" …>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="www.newton.com"/>
<data android:scheme="https" android:host="www.newton.com"/>
</intent-filter>
</activity>
4.应用链接设置和管理
为了方便管理,就可以进入系统设置,并通过导航来调整URL处理 Settings | Apps | App info | Open by default.
5.检查清单和列出域
我们的第一步是走过去的清单,并确保所有的域正确注册,所有意图过滤器很好的界定。只有在在下面的条目中提到的所有标准链接/域都是我们需要测试的:
android:scheme :用一个价值scheme属性HTTP或HTTPS
android:host :与域URI模式主机属性
类元素,它可以是以下之一:
android.intent.action.VIEW
android.intent.category.BROWSABLE
5.数字素材资源API链接
我们可以使用数字素材资源链接API来证实我们的链接的JSON文件是正确的和使用下面的语法定义的:
https://digitalassetlinks.googleapis.com/v1/statements:list?
source.web.site=https://<DOMAIN>:<port>&
relation=delegate_permission/common.handle_all_urls
6.测试我们的intent
adb shell am start -a android.intent.action.VIEW \ -c
android.intent.category.BROWSABLE \ -d "http://<DOMAIN>:<port>"
例如我们打开一个youtube视频,
adb shell am start -a android.intent.action.VIEW -c
android.intent.category.BROWSABLE -d "http://youtu.be/U9tw5ypqEN0"
7.用adb检查政策
adb shell dumpsys package domain-preferred-apps
adb shell dumpsys package d