在棒棒糖上,如果用户设置了个人识别码,那么一些通知就不能被刷走。当他们试图被解雇时,他们就像是一个持久的通知。
一些应用程序的通知可以在锁屏上滑动而不解锁。
我只测试了隐藏敏感通知内容,设置标志会改变这个能力吗?
我该如何实现这一点?
发布于 2015-08-28 01:56:18
这个标志让你的通知固定不变: Notification.FLAG_ONGOING_EVENT;
如果您将其省略,则可以将其删除。如果你把它放进去,它就会粘住。
仅供参考:我如何发出通知:
//These are parameters for setting up the tag in the tray
private static final String NOTIFICATION_ID_TAG="notificationID";
private static final int NOTIFICATION_ID=123456;
public void createNotification() {
// Prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, MainActivity_Host.class);
intent.putExtra(NOTIFICATION_ID_TAG, NOTIFICATION_ID);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Build notification
Notification noti = new Notification.Builder(this)
.setContentTitle("Service Running")
.setContentText("The service is running").setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//THIS FLAG MAKES THE NOTIFICATION STICK = YOU CAN'T SWIPE IT AWAY... IF YOU LEAVE IT OUT YOU CAN REMOVE THE NOTIFICATION
noti.flags |= Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(NOTIFICATION_ID, noti);
}下面是从代码中删除通知的方法:
//Erase the notification that we set up when the service started
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(NOTIFICATION_ID);如您所见,您可以通过用于创建通知的NOTIFICATION_ID从NotificationManager获取通知。这只是我编的一个数字。
https://stackoverflow.com/questions/32255726
复制相似问题