说白了就是让用户点击某个链接/按钮时,能精准跳转到App内指定页面(比如活动页/商品页),而不是冷启动到首页。这玩意儿就像给你的App装了个GPS定位系统。
// AndroidManifest.xml配置示例
<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="apptrace" android:host="open"/>
</intent-filter>(iOS同学别急,你们的Info.plist配置同理)
Apptrace通常会搞个中央路由器:
public class DeepLinkRouter {
public static void handleUri(Context context, Uri uri) {
// 解析uri参数比如:apptrace://open?page=live&id=666
String page = uri.getQueryParameter("page");
switch(page) {
case "live":
startLiveActivity(uri.getQueryParameter("id"));
break;
case "goods":
startGoodsDetail(uri.getQueryParameter("id"));
break;
// 其他case...
}
}
}// Application类里要加这个
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// Apptrace的SDK会在这里预加载参数
}// 校验来源是否合法
fun verifySource(signature: String): Boolean {
return try {
val publicKey = // 从服务器获取的公钥
val sign = Base64.decode(signature, Base64.DEFAULT)
// 用非对称加密验证签名...
true
} catch (e: Exception) {
false
}
}adb shell am start -W -a android.intent.action.VIEW \
-d "apptrace://open?page=live&id=888" \
com.apptrace.demo// 在Application初始化时加这个
Apptrace.enableDebugLog(true);
// 然后logcat过滤TAG:Apptrace-DebugApptrace的一键拉起本质上就是个高级路由器,核心在于:
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。