Android11版本中,当通知被取消或点击时,Notification.DeleteIntent收到了回调。当被点击时,不应该调用它。
创始人
2024-08-20 10:00:12
0

Android 11中的通知行为发生了变化。当通知被点击时,DeleteIntent不应该被触发。如果你想在通知被点击时执行某些操作,则可以使用PendingIntent。下面是示例代码:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
        .setContentTitle(title)
        .setContentText(body)
        .setSmallIcon(R.drawable.notification_icon);

// Create the intent that should be sent when the notification is clicked
Intent resultIntent = new Intent(context, MyActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntentWithParentStack(resultIntent);
PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

// Set the intent that should be sent when the notification is dismissed
builder.setDeleteIntent(resultPendingIntent);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(notificationId, builder.build());

在上述代码中,我们使用TaskStackBuilder来创建一个包含我们想要启动的Activity的Intent,并将其添加到堆栈中。我们还使用PendingIntent.FLAG_UPDATE_CURRENT标志来确保PendingIntent中的数据是最新的。最后,我们使用setDeleteIntent()方法将PendingIntent设置为在通知被消除时发送。这样,当用户点击通知时,应用程序会启动相应的Activity,而不是调用DeleteIntent。

相关内容

热门资讯

反观!wejoker辅助软件价... 反观!wejoker辅助软件价格(透视)一直是真的辅助安装(有挂方式)-哔哩哔哩1、让任何用户在无需...
今天下午!newpoker脚本... 今天下午!newpoker脚本(透视)都是有辅助修改器(真是有挂)-哔哩哔哩newpoker脚本脚本...
透视辅助!拱趴大菠萝怎么开挂(... 透视辅助!拱趴大菠萝怎么开挂(透视)本来存在有辅助安装(有挂详细)-哔哩哔哩拱趴大菠萝怎么开挂辅助器...
昨日!破解辅助插件wepoke... 昨日!破解辅助插件wepoker(透视)本来有辅助插件(有挂助手)-哔哩哔哩1、破解辅助插件wepo...
据目击者称!poker wor... 据目击者称!poker world辅助器(透视)确实有辅助辅助器(有挂秘诀)-哔哩哔哩1、游戏颠覆性...
围绕透视问题!wpk软件是正规... 围绕透视问题!wpk软件是正规的吗(透视)本来是有辅助安装(有挂秘诀)-哔哩哔哩1、金币登录送、破产...
透视免费!哈糖大菠萝软件下载(... 透视免费!哈糖大菠萝软件下载(透视)都是真的是有辅助神器(有挂分享)-哔哩哔哩1、哈糖大菠萝软件下载...
透视实锤!wepoker有没有... 透视实锤!wepoker有没有挂(透视)切实是有辅助下载(真实有挂)-哔哩哔哩所有人都在同一条线上,...
透视黑科技!佛手大菠萝13道挂... 透视黑科技!佛手大菠萝13道挂哪里(透视)竟然真的有辅助辅助器(有挂方针)-哔哩哔哩1、透视黑科技!...
透视能赢!wpk辅助哪里买(透... 透视能赢!wpk辅助哪里买(透视)本来真的有辅助app(有挂解密)-哔哩哔哩wpk辅助哪里买辅助器是...