NotificationChannel - How to show a notification for a while then hide it?
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?

add a comment |
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?

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
add a comment |
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?

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?


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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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);
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
add a comment |
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);
add a comment |
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);
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);
answered Jan 3 at 12:18
urukhurukh
9510
9510
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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