How to remove notification from notification bar programmatically in android?

后端 未结 4 734
旧时难觅i
旧时难觅i 2020-12-04 11:56

Anybody have idea how can we remove notification from application programmatically which is called using Pending intent.

I have used to cancel notification using fol

4条回答
  •  佛祖请我去吃肉
    2020-12-04 12:18

    Notifications remain visible until one of the following happens:

    The user dismisses the notification either individually or by using "Clear All" (if the notification can be cleared). The user clicks the notification, and you called setAutoCancel() when you created the notification. You call cancel() for a specific notification ID. This method also deletes ongoing notifications. You call cancelAll(), which removes all of the notifications you previously issued. If you set a timeout when creating a notification using setTimeoutAfter(), the system cancels the notification after the specified duration elapses. If required, you can cancel a notification before the specified timeout duration elapse

    public void cancelNotification() {
    
        String ns = NOTIFICATION_SERVICE;
        NotificationManager nMgr = (NotificationManager) getActivity().getApplicationContext().getSystemService(ns);
        nMgr.cancel(NOTIFICATION_ID);
    }
    

提交回复
热议问题