如何在锁屏上使android棒棒糖通知被解雇?

时间:2015-08-27 17:21:57

标签: android android-5.0-lollipop

在棒棒糖上,如果用户设置了针脚,则无法刷掉某些通知。当他们被解雇时,他们就像一个持久的通知。

某些应用通知可以在锁定屏幕上轻扫而无需解锁。

我只使用隐藏敏感通知内容对此进行了测试,标志设置是否会更改此功能?

我如何实现这一目标?

1 个答案:

答案 0 :(得分:1)

此标志会使您的通知贴上: 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获取通知。这只是我编写的一个数字。