赞
踩
前言
2015年5月28日,Google I/O大会上正式推出Android M(android6.0 API级别23),其中新增了一个特性叫AppLinks,它可以加强软件间的关联,可以把触屏端的流量带到移动端来。
Android App Links具有以下优势:
官方链接:https://developer.android.com/training/app-links/
接下来我们就讲讲如何把App Links功能应用到我们的程式
1.首先在配置文件AndroidManifest.xml中声明ApplinksActivity
- <activity
- android:name="这里填写包名.ApplinksActivity"
- android:alwaysRetainTaskState="true"
- android:launchMode="singleTask"
- android:noHistory="true"
- android:theme="@android:style/Theme.Translucent.NoTitleBar">
- <intent-filter android:autoVerify="true">
- <data
- android:host="这里填写域名"
- android:scheme="http" />
- <data
- android:host="这里填写域名"
- android:scheme="https" />
- ....
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="android.intent.category.BROWSABLE" />
- <action android:name="android.intent.action.VIEW" />
- </intent-filter>
- </activity>
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
2.然后在ApplinksActivity.java中处理链接跳转逻辑
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); Uri uri = intent.getData(); String host = uri.getHost(); String path = uri.getPath(); if (host.equals("这里填写域名")){ if(path.equals("链接路径")) { // 跳转app指定A界面 } else if(path.equals("链接路径")) { // 跳转app指定B界面 } else { ... } } }
以上为app端的配置,这个时候用户使用google浏览器访问了你配置声明好的域名时,它会弹出对话框询问你开启方式,如果用户点击选中了你的客户端时,那么它可以直接把你在浏览器中访问的链接带到app中进行操作。
如果你不希望弹出这个对话框,而是希望用户直接进入到你的app中,那么你还需要这两步操作进行认证:
1.生成assetlinks.json文件,
2.把这个文件上传到这里→ https://这里填写域名/.well-known/assetlinks.json
assetlinks.json文件格式:
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target" : { "namespace": "android_app",
"package_name": "这里填写应用程式的包名",
"sha256_cert_fingerprints": ["这里填写SHA256证书指纹"] }
}]
SHA256证书指纹获取方式:
在Androidstudio的Terminal下输入: keytool -list -v -keystore 这里填写应用程式签名文件的完整路径
AppLinks更多信息,请参阅安卓官方链接:https://developer.android.com/training/app-links/verify-site-associations
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。