0

a while back I updated my App to add support for Android 8+, after updating the notifications to use the required NotificationChannel I noticed that I lost a feature.
The App uses a chronometer notification, back then I was able to update the Notification priority, to display a notification using PRIORITY_HIGH, so the notification was "pushed" to the user, and then edit the notification priority to PRIORITY_LOW, to hide the notification.

After reading the docs, from what I could understand, I can't control the priority after creating the NotificationChannel, leaving this control to the user, however, asking for the user to edit the notification settings is not optimal for my usage.

Relevant code:

//Creating the notification channel (while setting up the app)
NotificationChannel channel = new NotificationChannel(channelId, channelTitle, NotificationManager.IMPORTANCE_HIGH);

//Editing the NotificationChannel to lower the Notification priority (not working)
NotificationChannel channel = notificationManager.getNotificationChannel(channelId);
channel.setImportance(NotificationManager.IMPORTANCE_LOW);     
notificationManager.createNotificationChannel(channel);

Is there a way accomplish this behavior, while still using the NotificationChannels?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
urukh
  • 360
  • 1
  • 3
  • 17
  • 2
    Maybe you could have two notification channels with different priorities/importance? – Joey Dalu Jan 02 '19 at 18:18
  • @JoeyDalu yeah, I thought about that, but having to setup a channel just for this seems kind of weird, however, if this is the only option i might have to.. haha – urukh Jan 02 '19 at 18:22

1 Answers1

0

Turns out I was overthinking this (by a lot), simply adding the option setOnlyAlertOnce on the NotificationBuilder, while still using the NotificationManager.IMPORTANCE_HIGH to setup the channel, will result on the expected behavior, like so:

NotificationCompat.Builder notificationBuilder = 
    new NotificationCompat.Builder(context, channelId).setOnlyAlertOnce(true);
urukh
  • 360
  • 1
  • 3
  • 17