我想显示一个不可关闭的通知,并且仅在以编程方式延迟一段时间后才将其关闭。我尝试了以下方法:
RemoteViews bigView = new RemoteViews(context.getPackageName(),
R.layout.big_notification);
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCustomHeadsUpContentView(bigView)
.setTicker("aaa")
.setOngoing(true);
notificationManager.notify(id, builder.build());
removeNotification(notificationManager, id);
}
private static void removeNotification(final NotificationManager notificationManager, final int id) {
Handler handler = new Handler();
long delayInMilliseconds = 4000;
handler.postDelayed(new Runnable() {
public void run() {
notificationManager.cancel(id);
}
}, delayInMilliseconds);
}
但是通知可以被用户刷掉……有什么想法吗?
最佳答案
试试这个:
notification.flags = Notification.FLAG_NO_CLEAR;
关于android - 正在进行的通知可以忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45983926/