Delete notification when addAction is called?

I add two action buttons to my notification, when I click on them, they perform the required action, but the notification remains in my notification box. I know that you can delete a notification from the notification box when you click the action button, since Gmail is functioning. If I click the main notification, it will open the application and delete the notification from the notification box.

Here is a snippet of my code:

Intent completeIntent = new Intent(getApplicationContext(), MarkComplete.class); completeIntent.putExtra("rowid", inrowid); completeIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent markCompleteIntent = PendingIntent.getActivity(getApplicationContext(), inrow, completeIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Title") .setContentText("text") .setContentIntent(notificationReleaseIntent) .setPriority(Notification.PRIORITY_HIGH) .setAutoCancel(true) .addAction(R.drawable.complete, "Mark Complete", markCompleteIntent); 

Edit - As Zionpi pointed out, I needed to call notification.cancel (); to delete a notification after clicking the addAction button. I just added this method to my classes, where I pointed out PendingIntent.

 public static void CancelNotification(Context ctx, int notifyId) { String s = Context.NOTIFICATION_SERVICE; NotificationManager mNM = (NotificationManager) ctx.getSystemService(s); mNM.cancel(notifyId); } 
+7
android notifications
source share
1 answer

So, you want to delete your notification, preliminary - to have a notification identifier.
then call a method like the one below to fix it.

  public static void CancelNotification(Context ctx, int notifyId) { String s = Context.NOTIFICATION_SERVICE; NotificationManager mNM = (NotificationManager) ctx.getSystemService(s); mNM.cancel(notifyId); } 

You might want to address these and.

+4
source share

All Articles