Search code examples
androidfirebaseandroid-notifications

How to remove notification from status bar when clicking the my footer icon


I want to remove the notification from status bar when clicking on footer icon. How to call this method outside the service class:

 mNotificationManager.cancel(MY_NOTIFICATION_ID); 

Is there any other solution to remove notification by clicking the custom button?


Solution

  • You can call the notification outside service class (such as activity using button click) in this way:

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancel(MY_NOTIFICATION_ID);
    

    You can see the detail of it at https://developer.android.com/training/notify-user/build-notification#Removing.