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。

相关内容

热门资讯

透视ai代打!wepoker私... 透视ai代打!wepoker私人辅助器(透视)杭州都莱app有辅助吗(确实存在有辅助插件)-哔哩哔哩...
此事迅速冲上热搜!约局吧德州有... 此事迅速冲上热搜!约局吧德州有挂吗(透视)雀友会广东潮汕麻雀开挂(好像是真的辅助下载)-哔哩哔哩1、...
围绕透视问题!德州机器人代打脚... 围绕透视问题!德州机器人代打脚本(透视)对战互娱怎么开辅助(原来存在有辅助辅助器)-哔哩哔哩1、游戏...
透视挂透视!epoker有透视... 您好,新众乐辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这...
近日!红龙poker有辅助吗(... 近日!红龙poker有辅助吗(透视)新道游辅助软件下载(总是真的有辅助安装)-哔哩哔哩新道游辅助软件...
经调查!破解辅助插件wepok... 经调查!破解辅助插件wepoker(透视)悟空大厅辅助器(果然真的是有辅助辅助器)-哔哩哔哩亲,关键...
据统计!hh poker辅助有... 据统计!hh poker辅助有用吗(透视)创思维辅助器(其实有辅助神器)-哔哩哔哩1、让任何用户在无...
此事备受玩家关注!hhpoke... 此事备受玩家关注!hhpoker有后台操控吗(透视)雀神挂件价格(竟然是有辅助插件)-哔哩哔哩1、雀...
连日来!wepoker辅助器激... 连日来!wepoker辅助器激活码(透视)闲来辅助工具(确实是有辅助工具)-哔哩哔哩1、完成闲来辅助...
透视代打!wepoker底牌透... 透视代打!wepoker底牌透视脚本(透视)潮友会鱼虾蟹怎么发现软件控制(原来存在有辅助下载)-哔哩...