Android 12中Deep Link通知异常:点击通知无法打开应用
Android 12上Firebase通知Deep Link未启动应用时跳转失效的解决方案
问题复现场景
- 应用未启动时,点击Firebase推送通知,无法打开应用并跳转到Deep Link指定页面
- 此前点击过该通知后,手动打开应用时Deep Link会触发跳转
- 应用处于前台/后台时,点击通知跳转功能正常
- 已升级
firebaseBomVersion至31.0.2,问题仍存在
针对性解决方案
1. 检查PendingIntent的Flag配置(关键)
Android 12对PendingIntent的flag有更严格的要求,应用未启动时需确保使用正确的flag组合:
- 启动Activity的
PendingIntent需结合FLAG_IMMUTABLE/FLAG_MUTABLE,同时添加FLAG_ACTIVITY_NEW_TASK和适配业务的启动flag(如FLAG_ACTIVITY_CLEAR_TOP) - 示例代码:
val pendingIntent = PendingIntent.getActivity( context, notificationId, deepLinkIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ACTIVITY_NEW_TASK or PendingIntent.FLAG_ACTIVITY_CLEAR_TOP )
注:需动态更新Intent数据时用
FLAG_MUTABLE,否则优先用Android 12+推荐的FLAG_IMMUTABLE
2. 验证Deep Link的Intent Filter配置
确保AndroidManifest中目标Activity的配置符合要求:
- 必须设置
android:autoVerify="true"(用于App Links验证) - 目标Activity需添加
android:exported="true"(Android 12+要求外部启动的Activity必须开放) - 包含正确的
scheme、host、pathPattern,以及DEFAULT和BROWSABLE类别
示例配置:
<activity android:name=".ui.target.TargetActivity" android:exported="true"> <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" /> <data android:scheme="yourapp" android:host="yourhost" android:pathPattern="/target/.*" /> </intent-filter> </activity>
3. 检查Firebase通知Payload设置
确保推送payload的Deep Link配置无冲突:
- 优先通过
data字段传递Deep Link信息,在自定义FirebaseMessagingService中统一处理跳转逻辑 - 若使用
notification字段,需保证click_action指向正确的目标Activity,避免与data字段的跳转逻辑冲突
4. 排查应用启动模式冲突
若目标Activity使用singleInstance/singleTask等特殊启动模式,可能导致未启动时跳转异常:
- 可临时改为
standard模式测试是否恢复正常 - 若必须保留特殊启动模式,需在Activity的
onNewIntent方法中手动解析Deep Link数据,确保跳转逻辑执行
5. 规避Android 12通知跳转限制
Android 12禁止通知跳转时的trampoline行为:
- 直接通过PendingIntent启动目标Activity,避免通过中间Service/BroadcastReceiver间接跳转
内容的提问来源于stack exchange,提问作者Tehleel Mir
相关产品推荐
相关产品推荐

