1

I have added addAction to my android notification to let the user start a specific activity , it is working but the notification doesn't get cleared onclick , while it's cleared when i click the notification not the button

 Intent openPostIntent = new Intent(getApplicationContext(), PostActivity.class);
        openPostIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        openPostIntent.setAction(Intent.ACTION_MAIN);
        openPostIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        openPostIntent.putExtra(POST_ID_KEY, post_id);
        PendingIntent open_post_pi = PendingIntent.getActivity(getApplicationContext(),
                1, openPostIntent, PendingIntent.FLAG_CANCEL_CURRENT);

Notification

NotificationCompat.Builder status = new NotificationCompat.Builder(getApplicationContext(),CHANNEL_ID);

       status.setAutoCancel(true)
               .setWhen(System.currentTimeMillis())
               .setSmallIcon(R.drawable.ic_stat_name)
               .setAutoCancel(true)
               .setOnlyAlertOnce(true)
               .setContentTitle(notification_title)
               .setContentText(message)
               .setLargeIcon(profile_img)
               .setDefaults(Notification.DEFAULT_LIGHTS )
               .setPriority(NotificationCompat.PRIORITY_DEFAULT)
               .setCategory(NotificationCompat.CATEGORY_MESSAGE)
               .setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
               .addAction(R.drawable.ic_post, "Open post", open_post_pi)
               .setContentIntent(pendingIntent);
``
Sneha
  • 94
  • 10
AYMEN SOUMER
  • 175
  • 2
  • 8
  • https://stackoverflow.com/questions/11883534/how-to-dismiss-notification-after-action-has-been-clicked – ADM May 02 '20 at 03:21

0 Answers0