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。

相关内容

热门资讯

一分钟了解!hhpoker是正... 一分钟了解!hhpoker是正品吗,wepoker破解器激活码,总是是有挂(存在有挂)进入游戏-大厅...
推荐十款!hhpoker是真的... 推荐十款!hhpoker是真的吗,wpk辅助软件,切实有挂(有挂方式)暗藏猫腻,小编详细说明破解器有...
总算了解!pokermaste... 总算了解!pokermaster脚本,德普辅助app,都是真的有挂(有挂秘诀)1、游戏颠覆性的策略玩...
详细说明!wepoker作弊辅... 详细说明!wepoker作弊辅助,hhpoker有透视功能吗,确实是有挂(有挂方针)1、公共底牌简单...
大神推荐!wepoker透视脚... 大神推荐!wepoker透视脚本,wpk软件是真的吗,真是存在有挂(存在有挂)大神推荐!wepoke...
盘点十款!wpk有辅助器吗,w... 盘点十款!wpk有辅助器吗,wpk辅助插件,果然有挂(有挂教学)1、盘点十款!wpk有辅助器吗,wp...
发现一款!德普之星透视辅助,w... 发现一款!德普之星透视辅助,we-poker靠谱吗,切实存在有挂(真的有挂)1、玩家可以在透视最简单...
重要通知!aapoker如何设... 重要通知!aapoker如何设置胜率,wejoker内置辅助,确实是有挂(有挂存在)1、玩家可以在线...
玩家实测!wejoker辅助软... 玩家实测!wejoker辅助软件视频,如何下载wepoker安装包,其实存在有挂(有挂讲解)破解侠是...
必备攻略!微扑克辅助下载,wp... 必备攻略!微扑克辅助下载,wpk辅助哪里买,好像真的是有挂(果真有挂)1、用户打开应用后不用登录就可...