0

I created a notification but once I click on it it does not remove! I even tried notification.setAutoCancel(true) and notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL

Here is my code:

notification.setSmallIcon(R.drawable.message64);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.setSound(uri);

Resources resources = getApplicationContext().getResources(),
            systemResources = Resources.getSystem();
notification.setTicker("Notification");
notification.setContentTitle("Nouveau message");
notification.setContentText("Vous avez reçu un nouveau message. ");
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(uniqueID,notification.build());

It is working well but it still doesn't remove it when I click on it.

Rino
  • 1,215
  • 1
  • 16
  • 28
Ayech Hamza
  • 159
  • 2
  • 10

1 Answers1

0
 NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setWhen(System.currentTimeMillis())
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                    R.mipmap.ic_launcher))
            .setContentTitle(getString(R.string.app_name))
            .setAutoCancel(true)

            .setContentText("Test")



    getManager().notify(ID, builder.build());

Using setAutoCancel(true) does notification clear on click

Jarvis
  • 1,714
  • 2
  • 20
  • 35