NotificationChannel - How to show a notification for a while then hide it?












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?










share|improve this question




















  • 2





    Maybe you could have two notification channels with different priorities/importance?

    – Joey Dalu
    Jan 2 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 2 at 18:22
















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?










share|improve this question




















  • 2





    Maybe you could have two notification channels with different priorities/importance?

    – Joey Dalu
    Jan 2 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 2 at 18:22














0












0








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?










share|improve this question
















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?







android notifications notification-channel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 18:13









Fantômas

32.8k156490




32.8k156490










asked Jan 2 at 17:50









urukhurukh

9510




9510








  • 2





    Maybe you could have two notification channels with different priorities/importance?

    – Joey Dalu
    Jan 2 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 2 at 18:22














  • 2





    Maybe you could have two notification channels with different priorities/importance?

    – Joey Dalu
    Jan 2 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 2 at 18:22








2




2





Maybe you could have two notification channels with different priorities/importance?

– Joey Dalu
Jan 2 at 18:18







Maybe you could have two notification channels with different priorities/importance?

– Joey Dalu
Jan 2 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 2 at 18:22





@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 2 at 18:22












1 Answer
1






active

oldest

votes


















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);





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010916%2fnotificationchannel-how-to-show-a-notification-for-a-while-then-hide-it%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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);





    share|improve this answer




























      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);





      share|improve this answer


























        0












        0








        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);





        share|improve this answer













        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);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 12:18









        urukhurukh

        9510




        9510
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54010916%2fnotificationchannel-how-to-show-a-notification-for-a-while-then-hide-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith