uni-app Android12及以上版本手机创建通知栏消息后,将app切到后台运行点击消息打不开app
uni-app Android12及以上版本手机创建通知栏消息后,将app切到后台运行点击消息打不开app
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Mac | macOS 13.2.1 | HBuilderX |
示例代码:
const msg = {
UUID: "androidPushMsgxxx",
title: "testTitle",
appid: "UNIxxx",
content: "Thought you might enjoy a little surprise... ",
payload: 'test',
}
plus.push.createMessage(msg.title, msg.payload, {title: msg.title});
操作步骤:
- Android12及以上版本手机创建通知栏消息后,将app切到后台运行,点击消息,此时打不开app
预期结果:
- 点击消息正常打开app
实际结果:
- 后台运行的app通过点击通知栏消息不能正常唤起
bug描述:
在使用unipushv1.0FCM推送时,app在后台运行时点击通知栏消息后打不开app,但是看log日志click监听是触发了 ,同时logcat里报的是这个错误: Indirect notification activity start (trampoline) from xxx blocked 看了下是Android12加了trampoline限制导致的,但是不知道该怎么去解决~
4 回复
目前用的也是链接里所写的intent开头,intent://io.dcloud.unipush/?#Intent;scheme=unipush;launchFlags=0x4000000;component=com.xxx.xx/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=你好;S.content=你好;S.payload={“payload”:{“id”:“xxx”}:;end ,华为渠道我们没有做,目前只有谷歌渠道
有解决吗?
在 Android 12 及以上版本中,由于系统的权限管理和后台限制更加严格,可能会导致通过通知栏消息无法正常唤醒应用的问题。以下是一些可能的原因和解决方案:
1. 检查通知权限
- 确保应用已经获取了通知权限。在 Android 12 及以上版本中,通知权限需要用户手动授予。
- 可以在应用的设置页面中检查通知权限是否已开启。
2. 使用 PendingIntent
设置正确的 Intent
- 确保在创建通知时,使用
PendingIntent
设置了正确的Intent
,并且Intent
的目标 Activity 是正确的。 - 例如:
Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
3. 处理后台启动限制
- Android 12 及以上版本对后台启动 Activity 进行了限制。如果应用在后台时,通过通知栏消息启动 Activity,可能会导致无法正常启动。
- 可以尝试使用
PendingIntent
的FLAG_IMMUTABLE
或FLAG_MUTABLE
标志来处理这个问题。PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);