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。

相关内容

热门资讯

此事引发网友热议!pokemm... 此事引发网友热议!pokemmo手机版脚本,德普之星透视辅助插件,总是确实有挂(有挂方针)1、完成德...
针对!wepoker怎么挂飞机... 针对!wepoker怎么挂飞机,德扑之星私人局透视,好像是有挂(有挂教学)1、下载好德扑之星私人局透...
据权威媒体报道!aapoker... 据权威媒体报道!aapoker发牌逻辑,德普之星有透视辅助吗,总是真的有挂(详细教程)1、德普之星有...
据悉!wpk俱乐部是真的吗,德... 据悉!wpk俱乐部是真的吗,德扑之星透视辅助插件,一直真的是有挂(有挂分析)1、该软件可以轻松地帮助...
教学辅助挂!德普之星透视软件免... 教学辅助挂!德普之星透视软件免费入口官网,德扑之星透视免费,原来确实有挂(有挂头条)1、这是跨平台的...
据相关数据显示!wepoker... 据相关数据显示!wepoker透视脚本免费,德扑圈透视挂,原来真的有挂(真的有挂)1、德扑圈透视挂脚...
黑科技辅助挂!wepoker透... 黑科技辅助挂!wepoker透视有用吗,德普辅助软件,竟然真的有挂(有挂秘笈)1)德普辅助软件免费钻...
近期!hhpoker软件安装包... 近期!hhpoker软件安装包,红龙poker辅助,果然是有挂(有挂猫腻)红龙poker辅助透视方法...
受玩家影响!约局吧怎么看有没有... 受玩家影响!约局吧怎么看有没有挂,德扑之心免费透视,切实真的有挂(有挂细节)1、每一步都需要思考,不...
今天上午!wepoker模拟器... 今天上午!wepoker模拟器哪个好用,德扑之心免费透视,真是确实有挂(有挂详情)1、这是跨平台的德...