Remove the notification icon from the status bar

后端 未结 4 987
说谎
说谎 2020-12-01 15:07

I am displaying an icon in status bar.Now I want to remove that icon immediately when I open that content, after some time if we receive any alert, that icon will be display

4条回答
  •  春和景丽
    2020-12-01 15:23

    Use the NotificationManager to cancel your notification. You only need to provide your notification id.

    https://developer.android.com/reference/android/app/NotificationManager.html

    private static final int MY_NOTIFICATION_ID= 1234;
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager;
    mNotificationManager = (NotificationManager) getSystemService(ns);
    mNotificationManager.notify(MY_NOTIFICATION_ID, notification);
    

    The example code is not complete. It depends on how your created your notification. Just make sure you use the same id to cancel your notification as you used when you created your notification.

    To cancel:

    mNotificationManager.cancel(MY_NOTIFICATION_ID);
    

提交回复
热议问题