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。

相关内容

热门资讯

做出回应!pokemmo内置修... 做出回应!pokemmo内置修改器,德普之星透视辅助软件是真的吗,果然是有挂(有挂方针)1、点击下载...
最强版hhpoker是真的吗,... 最强版hhpoker是真的吗,德普之星有透视辅助吗,竟然真的是有挂(竟然有挂)在进入软件靠谱后,参与...
据了解!德普之星透视辅助软件激... 据了解!德普之星透视辅助软件激活码,智星德州辅助译码插件靠谱吗,好像真的是有挂(有挂规律)1、进入到...
最强版德州透视脚本,wepok... 最强版德州透视脚本,wepoker私人局开挂视频,都是有挂(有挂秘籍)1、该软件可以轻松地帮助玩家将...
教学辅助挂!hhpoker有没... 教学辅助挂!hhpoker有没有外挂,德扑之星透视软件免费入口官网,切实真的是有挂(有挂助手)德扑之...
最强版wepoker辅助是真的... 最强版wepoker辅助是真的假的,hhpoker有作弊的吗,切实真的是有挂(有挂方略)最强版wep...
据了解!佛手在线大菠萝智能辅助... 据了解!佛手在线大菠萝智能辅助器,德普之星辅助工具如何设置,其实存在有挂(有挂助手)1、德普之星辅助...
最强版wepoker怎么提高运... 最强版wepoker怎么提高运气,wepoker黑侠辅助器,其实存在有挂(今日头条)1、透视辅助软件...
昨日!wepoker透视挂底牌... 昨日!wepoker透视挂底牌,德扑圈有透视吗,切实真的是有挂(揭秘有挂)小薇(辅助器软件下载)致您...
最强版wepoker辅助器软件... 最强版wepoker辅助器软件下载,拱趴大菠萝挂怎么安装,好像真的是有挂(有挂秘诀)1、操作简单,无...