Android 13中二维码DeepLink无法唤起应用问题求助
Android 13 Pixel 6 Pro相机识别DeepLink二维码后跳转浏览器而非应用的解决方案
问题背景
我用二维码承载自定义scheme的DeepLink,Android 12及以下版本识别后点击能正常打开我的应用,但在**Pixel 6 Pro(Android 13)**上,相机识别二维码后点击只会打开浏览器,无法跳转应用。Manifest里的Activity已经配置了scheme的intent-filter:
<activity android:name="com.mypackage.MyAcctivity" android:exported="true"> <intent-filter android:label="@string/app_name"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myScheme" /> </intent-filter> </activity>
试过添加pathPrefix或pathSuffix,但没有效果。
解决方法
1. 给intent-filter补充host约束
自定义scheme仅指定scheme时,浏览器也可能匹配到该intent-filter(浏览器会处理各类scheme)。给data标签加上host,让匹配逻辑更精准:
<intent-filter android:label="@string/app_name"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- host可自定义,比如设为"app",对应DeepLink格式需改为myScheme://app/xxx --> <data android:scheme="myScheme" android:host="app" /> </intent-filter>
同时将二维码中的DeepLink调整为myScheme://app/xxx格式,帮助系统更准确匹配到你的应用。
2. 打印Intent排查问题
在MyAcctivity中添加日志,确认相机传递的Intent内容:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { Log.d("DeepLinkCheck", "Scheme: " + intent.getScheme()); Log.d("DeepLinkCheck", "Full Data: " + intent.getDataString()); } // 原有业务代码 }
如果日志中未收到对应scheme的Intent,说明相机可能未正确发送VIEW动作,或者Intent被系统拦截。
3. 手动配置应用的链接关联
打开Pixel 6 Pro的系统设置,找到你的应用→默认应用→链接处理,检查是否将myScheme关联到你的应用。若未关联,手动添加后再测试。
4. 改用Android App Links(推荐)
如果业务允许,换成基于HTTPS的Android App Links,该方式在Android 13上兼容性更好,不会出现浏览器跳转问题。需完成以下配置:
- 使用HTTPS域名作为DeepLink(例如
https://yourdomain.com/xxx) - 在应用
res/xml目录下创建assetlinks.json,并上传至域名的.well-known目录 - 在Manifest中配置对应intent-filter,并添加
android:autoVerify="true"属性
内容的提问来源于stack exchange,提问作者Cib Ingenierie
相关产品推荐
相关产品推荐

