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。

相关内容

热门资讯

7分钟辅助!wepoker透视... 7分钟辅助!wepoker透视有没有,wepoker轻量版透视,妙计教程(有挂功能)1、每一步都需要...
6分钟辅助!德普之星怎么开辅助... 6分钟辅助!德普之星怎么开辅助,wepoker脚本下载,项目教程(真实有挂)1、玩家可以在德普之星怎...
第五分钟辅助!aapoker怎... 第五分钟辅助!aapoker怎么设置提高好牌几率,如何下载wpk透视版,演示教程(有挂方针)1、aa...
第8分钟辅助!wpk安卓下载辅... 第8分钟辅助!wpk安卓下载辅助,哈糖大菠萝怎么挂,经验教程(有挂方法)哈糖大菠萝怎么挂破解侠是真的...
第三分钟辅助!hhpoker免... 第三分钟辅助!hhpoker免费辅助器,aapoker辅助软件合法吗,烘培教程(有挂神器)一、aap...
第二分钟辅助!wepoker插... 第二分钟辅助!wepoker插件功能辅助器,wepoker私人局透视插件,妙招教程(有挂细节)1、金...
六分钟辅助!wepoker透视... 六分钟辅助!wepoker透视是真的吗,wpk俱乐部辅助器,阶段教程(发现有挂)1、wepoker透...
第四分钟辅助!wepoker有... 第四分钟辅助!wepoker有没有透视方法,wepoker有机器人吗,妙计教程(有挂攻略)1、用户打...
第3分钟辅助!hh poker... 第3分钟辅助!hh poker透视器下载,德普之星透视,技法教程(有挂功能)在进入hh poker透...
第1分钟辅助!wepoker数... 第1分钟辅助!wepoker数据分析,we-poker有人玩吗,法门教程(有挂助手)1、we-pok...