我正在使用 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/