Android平台Deep Link无法工作,按官方文档配置仍遇问题求助
看起来你贴的intent-filter代码没写完,先从几个核心点逐一排查:
补全Intent Filter的Category标签
你贴的代码里<category android:name="android.intent.category.D...明显截断了,Deep Link的intent-filter必须包含两个关键Category,缺了任何一个都可能导致系统无法匹配到你的Activity:<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" />DEFAULT让你的Activity能被隐式Intent唤起,BROWSABLE允许浏览器或其他应用通过链接启动它。务必添加
<data>标签
这是新手最容易忽略的点!Deep Link需要明确指定匹配的URL规则,比如scheme(http/https或自定义)、host、路径等,示例如下:<data android:scheme="http" android:host="www.yourdomain.com" android:pathPrefix="/gizmos" />没有这个标签,系统根本不知道哪些URL应该路由到你的GizmosActivity。
核对整个Manifest配置结构
确保你的Activity和intent-filter的嵌套完全正确,完整的配置示例应该是这样:<activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos"> <intent-filter android:label="@string/filter_view_http_gizmos"> <action android:name="android.intent.action.VIEW" /> <!-- 必须的两个Category --> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- 替换为你的实际URL规则 --> <data android:scheme="http" android:host="www.yourdomain.com" android:path="/gizmos" /> </intent-filter> </activity>用adb命令精准测试
不要只依赖网页链接测试,用adb命令直接触发Intent,能快速定位问题:adb shell am start -W -a android.intent.action.VIEW -d "http://www.yourdomain.com/gizmos" com.example.android如果adb能成功唤起Activity,那问题可能出在网页端的链接配置;如果adb也不行,那肯定是Manifest的配置有问题。
检查默认应用设置
如果有其他应用也匹配这个URL规则,系统可能会弹出选择器,或者你之前设置了其他应用作为默认处理程序,导致你的应用没被唤起。可以去系统设置里清除该URL类型的默认应用,再重新测试。适配Android 12+的权限要求
如果你针对的是Android 12(API 31)及以上版本,需要在Manifest里添加<queries>标签声明你要处理的URL scheme,或者添加QUERY_ALL_PACKAGES权限(如果是通用的http/https scheme):<queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:scheme="http" /> </intent> </queries>否则系统会限制你的应用被其他应用或浏览器唤起。
先从这些点逐一检查,应该能找到问题根源。
内容的提问来源于stack exchange,提问作者mipnw

