抬头通知在几秒钟后被解雇
Heads Up Notification getting dismissed after few second
我正在尝试通过下面的代码发出提醒通知,并希望它一直存在,直到用户决定关闭它。但它会在几秒钟后(大约 10 秒)自动消失。有没有办法让它持久化并留给用户关闭它。
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification")
.setContentText("Hello !!!")
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.addAction(R.drawable.ic_launcher,
"View Call", null)
.addAction(R.drawable.ic_launcher,
"Call Back", null);
// Gets an instance of the NotificationManager service
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
这段代码对我有用。
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent piDismiss = PendingIntent.getActivity(this, 0, intent, 0);
//build notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setCategory(Notification.CATEGORY_MESSAGE)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Ping Notification")
.setContentText("You have a new notification.")
.setDefaults(Notification.DEFAULT_ALL) // must requires VIBRATE permission
.setPriority(NotificationCompat.PRIORITY_DEFAULT) //must give priority to High, Max which will considered as heads-up notification
.addAction(R.drawable.dismiss,
"View Call", piDismiss)
.addAction(R.drawable.ic_ok,
"ok", null)
.setFullScreenIntent(piDismiss, true);
我正在尝试通过下面的代码发出提醒通知,并希望它一直存在,直到用户决定关闭它。但它会在几秒钟后(大约 10 秒)自动消失。有没有办法让它持久化并留给用户关闭它。
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification")
.setContentText("Hello !!!")
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.addAction(R.drawable.ic_launcher,
"View Call", null)
.addAction(R.drawable.ic_launcher,
"Call Back", null);
// Gets an instance of the NotificationManager service
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
这段代码对我有用。
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent piDismiss = PendingIntent.getActivity(this, 0, intent, 0);
//build notification
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setCategory(Notification.CATEGORY_MESSAGE)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Ping Notification")
.setContentText("You have a new notification.")
.setDefaults(Notification.DEFAULT_ALL) // must requires VIBRATE permission
.setPriority(NotificationCompat.PRIORITY_DEFAULT) //must give priority to High, Max which will considered as heads-up notification
.addAction(R.drawable.dismiss,
"View Call", piDismiss)
.addAction(R.drawable.ic_ok,
"ok", null)
.setFullScreenIntent(piDismiss, true);