我想显示一个不允许的通知,只有在编程延迟一段时间后才会将其解除。我尝试过以下方法:
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);
}
但是用户可以刷出通知......有什么想法吗?
答案 0 :(得分:0)
试试这个:
notification.flags = Notification.FLAG_NO_CLEAR;