Xamarin Android深度链接失效求助:点击链接未唤起应用/跳转Play Store
Xamarin Android App Links 配置问题解决方案
问题描述
- 开发Xamarin Android应用,已验证自定义共享链接的域名,部署至Play Store后,点击共享链接时,无论应用是否安装,均仅打开链接对应的域名,未实现已安装时唤起应用、未安装时跳转Play Store的预期效果。
- 尝试过以下3种链接格式,均无效:
app://abc.xyz.co.in?user=BXOKyvuohpfq8SChnAYvEg==&sightPathID=iPsDHHYxOZfr1x+iIHv/4Q==&app_package=com.xyz.android#Intent;scheme=https;endintent://abc.xyz.co.in?user=Od7NdFvTUnoY4HjwybJx1w==&flightID=J6l70jOaTcnvGYbJAYNkBg==&app_package=com.xyz.android#Intent;scheme=https;endhttps://abc.xyz.co.in?user=WO3CQXYZK1cjmz+icsMYcQ==&flightID=mZNid1APgem7d4LNVhunAg==&app_package=com.xyz.android#Intent;scheme=https;ends;end
- 已根据链接修改Manifest中的
intent-filter配置,运行环境为Android 14。
解决方案
一、修正Manifest的Intent-Filter配置
Android 12+对App Links的验证要求更严格,确保你的intent-filter符合以下标准:
- 必须添加
android:autoVerify="true",用于自动验证域名关联 - 明确指定
scheme="https"、host="abc.xyz.co.in",并配置匹配路径的规则 - 包含必要的action和category
示例配置(可直接编辑AndroidManifest.xml或通过Xamarin属性配置):
<activity android:name=".MainActivity"> <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" /> <!-- 匹配域名下所有路径,可根据需求调整pathPattern --> <data android:scheme="https" android:host="abc.xyz.co.in" android:pathPattern="/.*" /> </intent-filter> </activity>
二、配置Digital Asset Links文件
在你的域名根目录或.well-known文件夹下放置assetlinks.json文件,内容如下:
[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.xyz.android", "sha256_cert_fingerprints": ["你的应用Play Store签名SHA256指纹"] } }]
- SHA256指纹必须使用Play Console中应用签名的指纹,而非调试指纹
- 可通过Google官方工具验证文件有效性
三、使用标准HTTPS链接并添加网页跳转逻辑
你之前使用的带Intent后缀的链接格式已过时,直接使用标准HTTPS链接:https://abc.xyz.co.in?user=BXOKyvuohpfq8SChnAYvEg==&sightPathID=iPsDHHYxOZfr1x+iIHv/4Q==
当应用未安装时,点击链接会打开网页,需在网页中添加跳转Play Store的逻辑:
<script> window.addEventListener('load', function() { // 尝试唤起应用,1秒后未成功则跳转Play Store const intentUrl = `intent://abc.xyz.co.in${window.location.search}#Intent;scheme=https;package=com.xyz.android;end`; setTimeout(() => { window.location.href = 'https://play.google.com/store/apps/details?id=com.xyz.android'; }, 1000); window.location.href = intentUrl; }); </script>
四、在Xamarin应用中处理唤起链接
在MainActivity中重写方法获取链接参数:
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); ProcessDeepLink(Intent); } protected override void OnNewIntent(Intent intent) { base.OnNewIntent(intent); ProcessDeepLink(intent); } private void ProcessDeepLink(Intent intent) { if (intent?.Data == null) return; var userId = intent.Data.GetQueryParameter("user"); var sightPathId = intent.Data.GetQueryParameter("sightPathID"); // 这里添加参数处理逻辑 }
五、Android 14额外注意事项
- 若需手动检测应用安装状态,需申请
QUERY_ALL_PACKAGES权限(App Links自动唤起无需此权限) - 可通过
adb shell dumpsys package domain-preferred-apps命令检查App Links的验证状态
内容的提问来源于stack exchange,提问作者kashif jamshed
相关产品推荐
相关产品推荐

