Android Notification FLAG_AUTO_CANCEL not working

2019-07-16 13:16发布

问题:

HI all

I want cancel notification on click using code below but some reason it always shows notification in Ongoing section in Notifications area and could not clear too ..

  NOTIFICATION_ID = NOTIFICATION_ID + 1;
  Intent intent1 = new Intent(this, MyClass.class);
  PendingIntent pii = PendingIntent.getActivity(this, 1, intent1, 0);
  Notification notification1 = new Notification(R.drawable.icon, "test",
    System.currentTimeMillis());

  notification1.setLatestEventInfo(this,
    "test", "test", pii);

  notification1.flags |= Notification.FLAG_AUTO_CANCEL;
  startForeground(NOTIFICATION_ID, notification1);

thanks

回答1:

FLAG_AUTO_CLEAR does not work with startForeground().