0

I use the following code to create a notification, but the notification was cleared automatically by the system after minutes. I don't want to use builder.setOngoing() to keep it "alive", because it should be cleared manually by the user. How can I slove this?

ps: I found this problem on OnePlus device, but some apps notification can work well.

NotificationManager mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.mipmap.ic_launcher);
    builder.setShowWhen(true);
    builder.setWhen(System.currentTimeMillis());
    builder.setVisibility(Notification.VISIBILITY_PUBLIC);
    builder.setContentTitle("This is title");
    builder.setContentText("This is content");
    builder.setDefaults(Notification.DEFAULT_ALL);
    builder.setWhen(System.currentTimeMillis());

    mManager.notify((int) System.currentTimeMillis(), builder.build());
braX
  • 11,506
  • 5
  • 20
  • 33

0 Answers0