Ad

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?

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad