2013-10-17 48 views
5

有没有办法让用户在没有按下按钮的情况下清除通知?我已经设置setAutoCancel(false)并且没问题,但是有一个按钮可以清除所有通知,我不希望它清除我的通知,因为这对用户很重要,他必须阅读并选择操作。不要让用户清除android通知?

NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
     .setSmallIcon(R.drawable.icon) 
     .setContentTitle("Sync Failed") 
     .setContentText("Lorem ipsum dolor sit amet") 
     .setStyle(new NotificationCompat.BigTextStyle().bigText("Lorem ipsum dolor sit amet")) 
     .addAction(R.drawable.change, "Change Pass", pChangePass) 
     .addAction(R.drawable.remove, "Ignore", pIgnore) 
     .setAutoCancel(false); 


mNotificationManager.notify(accountUnique, builder.build()); 

回答

14
.setOngoing(true) 

也需要被加入!

1

对于改变你的最后三行代码这样的..

final Notification notification = builder.build(); 
notification.flags = Notification.FLAG_NO_CLEAR; 
mNotificationManager.notify(accountUnique, notification);