单击/滑动时不会取消 Android 通知

标签 android android-notifications

我正在使用 startForeground(id,notification) 从 Intent 服务创建通知。

Random r=new Random();
int id=r.nextInt(9999);

Builder notice2=new Notification.Builder(getApplicationContext())
    .setContentTitle(call.getName())
    .setAutoCancel(true)
    .setContentIntent(intent)
    .setContentText("content")
    .setSmallIcon(com.project.calltracker.R.drawable.ic_alert)
    .setLargeIcon(BitmapFactory.decodeResource(getResources(), com.project.calltracker.R.drawable.ic_logo));

startForeground(id, notice2.getNotification());

这里我设置了AutoCancel(true)

但是当我点击通知时它并没有消失??

我真的很困惑。我已经尝试了过去几个小时的所有方法,但仍然没有成功!

请帮忙!

谢谢!

最佳答案

我从我的另一篇文章的答案中找到了答案。基本上只能有一个前台服务。使用 startForeground() 生成通知意味着只要此服务正在运行,就无法删除通知。

而是使用 NotificationManager.notify() 简单地生成通知。为此通知设置 AutoCancel(true) 使其在滑动/点击时消失。

谢谢!

关于单击/滑动时不会取消 Android 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21511082/

相关文章:

android - 显示来自服务的 Toast 通知

android - 如何在 Android 5.0 Lollipop 中关闭固定屏幕时收到通知?

Android O - 关闭通知 channel 然后打开,重要性级别始终重置为中等

java - Android 返回旧的 Activity

android - android :configChanges ="screenSize" attribute do?是什么意思

安卓。未解析的引用 : repeatOnLifecycle

android - 无尽的回收者 View 重复 json 数据

java - 房间数据库实例无法解析 DAO 方法的符号

android - 如何让Android应用兼容不同的屏幕分辨率?

android - 如何在 API 23 之前获取 Activity 通知列表