Deep Links
当浏览器跳转到某个Uri时,Android系统弹出一个Dialog,列出所有能处理这个Uri跳转(Web Uri Intent)的应用。当用户选择某个应用,会跳转到被选择应用的指定页面。这样的Uri称作Deep Links。

创建一个Deep Link
假设从share://example/profile跳转到应用的ProfileActivity。
- 声明intent filters
<activity
android:name=".ProfileActivity"
android:label="@string/title_profile" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="share" android:host="example" />
</intent-filter>
</activity>
- 从intent获取数据
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
App Links
App Links是Deep Links的特例。App Links会直接跳转到指定应用的指定页面,省略了用户选择的步骤。

创建一个App Link
创建App Link比Deep Link多了一个校验步骤。 首先需要设置android:autoVerify="true"。
<activity ...>
<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.example.com" />
<data android:scheme="https" />
</intent-filter>
</activity>
然后生成一个assetlinks.json文件上传到服务器的https://[域名]/.well-known/assetlinks.json路径。
App Links可以通过Android Studio的工具App Links Assistant创建。官方教程在此 。