这周公司的需求,app端通过微信分享到朋友圈的链接,点击按钮调起app的指定页面
类似于下面的小例子
Scheme协议
Scheme是一种页面跳转协议,和网站通过URL的形式访问一样,APP同样可以通过这种方式进行跳转,它可以很方便的满足我们在一些场景中的需求:
- 当应用接收到Push,点击通知栏消息跳转到特定页面,比如商品详情等。
- 通过服务器下发的跳转路径,客户端可以根据路径跳转相应页面。
- 应用跳转到其他APP指定页面。
- H5页面点击锚点,APP端跳转具体页面
协议格式
Uri.parse("qh://test:8080/goods?goodsId=8897&name=fuck")
- qh代表Scheme协议名称 可以随便起名字
- test代表Scheme作用的地址域 一般使用包名
- 8080代表改路径的端口号 可以忽略
- /goods代表的是指定页面(路径) 可以忽略
- goodsId和name代表传递的两个参数 可以忽略
Scheme使用
用上面的demo做例子吧
- 定义一个Scheme
<activity android:name=".base.activity.SplashActivity"
android:theme="@style/TranslucentThemeBlack">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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:host="com.example"
android:scheme="wxdemo" />
</intent-filter>
</activity>
- 获取Scheme跳转的参数
Uri uri = getIntent().getData();
if (uri != null) {
// 完整的url信息
String s = uri.toString();
sb.append(s + "\n");
// scheme部分
String scheme = uri.getScheme();
sb.append("scheme=" + scheme + "\n");
// host部分
String host = uri.getHost();
sb.append("host=" + host + "\n");
// 访问路劲
String path = uri.getPath();
sb.append("path=" + path + "\n");
//port部分
int port = uri.getPort();
sb.append("port=" + port + "\n");
// Query部分
String query = uri.getQuery();
sb.append("query=" + query + "\n");
//获取指定参数值
String goodsId = uri.getQueryParameter("goodsId");
sb.append("goodsId=" + goodsId + "\n");
//列举所以参数名
Set<String> queryParameterNames = uri.getQueryParameterNames();
tv_scheme.setText(sb.toString());
}
原生拿到这些数据可以解析拿到想要的数据去自定义跳转,也可以通过
1. 原生调用
Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse("qh://test:8080/goods?goodsId=8897&name=fuck"));
startActivity(intent1);
客户端的已经完成了
html端的简单测试html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
< a href="wxandroid://包名/attr?id=5de4615abde0b33ed4104cdd">启动应用程序</ a>
</body>
</html>
然后就能成功了。
但是微信对android有限制!!!!!
微信对scheme有限制,不能直接通过微信打开app,必须要通过应用宝和第三方浏览器,并且,通过应用宝部分不够等级的app不能携带参数跳转到指定页面
够等级的需要去应用宝的客服申请applink权限,申请通过后就可以直接跳转到指定页面了。
如果你不要求跳转到指定页面 就可以直接从详情页跳转到应用宝,再从应用宝跳转到app。
下面是我整理的虎嗅app的工作流程图
哎,啥时候能跟ios是的。
限制都说清楚了,现在研究一下scheme的原理吧
可以看这个
https://www.cnblogs.com/mingfeng002/p/10579771.html