gpt4 book ai didi

android - 如何设置通知以在点击时自行清除?

转载 作者:太空狗 更新时间:2023-10-29 16:39:27 26 4
gpt4 key购买 nike

如何设置我的通知在点击时自行清除?

我已经设置了 autoCancel(true) 但它不起作用

我的代码:

Notification n  = new Notification.Builder(this)
.setContentTitle("Update for you")
.setContentText("Please click here to see the update information")
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
R.drawable.ic_launcher))
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pList)
.setAutoCancel(true)
.addAction(R.drawable.ic_read, "Read", pRead)
.addAction(R.drawable.ic_list, "All Updates", pList)
.build();

NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(0, n);

最佳答案

Notification.Builder

setAutoCancel()是API 11引入的,可能你的最低版本低于API 11。

setAutoCancel() 也可以在添加到支持库中的 NotificationCompat.Builder 类中使用

Notification n  = new NotificationCompat.Builder(this)
.setContentTitle("Update for you")
.setContentText("Please click here to see the update information")
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
R.drawable.ic_launcher))
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pList)
.setAutoCancel(true)
.addAction(R.drawable.ic_read, "Read", pRead)
.addAction(R.drawable.ic_list, "All Updates", pList)
.build();

关于android - 如何设置通知以在点击时自行清除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20558619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com