Notification Channel - Is It Possible to Change LightColor After It's Been Set?
I'm trying to change setLightColor
with a colour returned from a JavaScript Interface. Unfortunately, NotificationCompat.Builder(context, CHANNEL_ID).setLights
has absolutely no sway on API >= 26, so I can't use Intent.putExtra
or anything similar.
Is it even possible to change it after it's already been set? I would like it to be dynamic.
EDIT There seems to be some misconception on what I want. I don't want to touch the Broadcast Reciever
. It works just fine. I want to change the notification channel. It's not updating setLightColor(Color.___)
.
In protected void onCreate
String jobColor = someColor; // Will be filled in by other code - different colour every time
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel_Name";
String description = "Channel_Description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setLightColor(Color.parseColor(jobColor)); // Dynamically set from above
channel.enableVibration(true);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
My BroadcastReciever - setLight is not applicable for API 26 or higher I believe
public class AlarmReceiver extends BroadcastReceiver {
private final String CHANNEL_ID = "some_channel";
@Override
public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , new Intent(context, MainPage.class), 0);
String jobColor = intent.getStringExtra("jobColor");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("Upcoming Shift!")
.setContentText("Shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime"))
.setStyle(new NotificationCompat.BigTextStyle().bigText("You have a shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime")))
.setLights(Color.parseColor(jobColor), 10000, 1000)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(12345, mBuilder.build());
}
}
java android notifications channel led
add a comment |
I'm trying to change setLightColor
with a colour returned from a JavaScript Interface. Unfortunately, NotificationCompat.Builder(context, CHANNEL_ID).setLights
has absolutely no sway on API >= 26, so I can't use Intent.putExtra
or anything similar.
Is it even possible to change it after it's already been set? I would like it to be dynamic.
EDIT There seems to be some misconception on what I want. I don't want to touch the Broadcast Reciever
. It works just fine. I want to change the notification channel. It's not updating setLightColor(Color.___)
.
In protected void onCreate
String jobColor = someColor; // Will be filled in by other code - different colour every time
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel_Name";
String description = "Channel_Description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setLightColor(Color.parseColor(jobColor)); // Dynamically set from above
channel.enableVibration(true);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
My BroadcastReciever - setLight is not applicable for API 26 or higher I believe
public class AlarmReceiver extends BroadcastReceiver {
private final String CHANNEL_ID = "some_channel";
@Override
public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , new Intent(context, MainPage.class), 0);
String jobColor = intent.getStringExtra("jobColor");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("Upcoming Shift!")
.setContentText("Shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime"))
.setStyle(new NotificationCompat.BigTextStyle().bigText("You have a shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime")))
.setLights(Color.parseColor(jobColor), 10000, 1000)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(12345, mBuilder.build());
}
}
java android notifications channel led
update the notification every time when you want to update something in current.
– nidhi
Nov 13 '18 at 10:36
add a comment |
I'm trying to change setLightColor
with a colour returned from a JavaScript Interface. Unfortunately, NotificationCompat.Builder(context, CHANNEL_ID).setLights
has absolutely no sway on API >= 26, so I can't use Intent.putExtra
or anything similar.
Is it even possible to change it after it's already been set? I would like it to be dynamic.
EDIT There seems to be some misconception on what I want. I don't want to touch the Broadcast Reciever
. It works just fine. I want to change the notification channel. It's not updating setLightColor(Color.___)
.
In protected void onCreate
String jobColor = someColor; // Will be filled in by other code - different colour every time
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel_Name";
String description = "Channel_Description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setLightColor(Color.parseColor(jobColor)); // Dynamically set from above
channel.enableVibration(true);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
My BroadcastReciever - setLight is not applicable for API 26 or higher I believe
public class AlarmReceiver extends BroadcastReceiver {
private final String CHANNEL_ID = "some_channel";
@Override
public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , new Intent(context, MainPage.class), 0);
String jobColor = intent.getStringExtra("jobColor");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("Upcoming Shift!")
.setContentText("Shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime"))
.setStyle(new NotificationCompat.BigTextStyle().bigText("You have a shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime")))
.setLights(Color.parseColor(jobColor), 10000, 1000)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(12345, mBuilder.build());
}
}
java android notifications channel led
I'm trying to change setLightColor
with a colour returned from a JavaScript Interface. Unfortunately, NotificationCompat.Builder(context, CHANNEL_ID).setLights
has absolutely no sway on API >= 26, so I can't use Intent.putExtra
or anything similar.
Is it even possible to change it after it's already been set? I would like it to be dynamic.
EDIT There seems to be some misconception on what I want. I don't want to touch the Broadcast Reciever
. It works just fine. I want to change the notification channel. It's not updating setLightColor(Color.___)
.
In protected void onCreate
String jobColor = someColor; // Will be filled in by other code - different colour every time
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Channel_Name";
String description = "Channel_Description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
channel.enableLights(true);
channel.setLightColor(Color.parseColor(jobColor)); // Dynamically set from above
channel.enableVibration(true);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
My BroadcastReciever - setLight is not applicable for API 26 or higher I believe
public class AlarmReceiver extends BroadcastReceiver {
private final String CHANNEL_ID = "some_channel";
@Override
public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 , new Intent(context, MainPage.class), 0);
String jobColor = intent.getStringExtra("jobColor");
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("Upcoming Shift!")
.setContentText("Shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime"))
.setStyle(new NotificationCompat.BigTextStyle().bigText("You have a shift at " + intent.getStringExtra("jobName") + " on " + intent.getStringExtra("jobDate") + " at " + intent.getStringExtra("jobTime")))
.setLights(Color.parseColor(jobColor), 10000, 1000)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(12345, mBuilder.build());
}
}
java android notifications channel led
java android notifications channel led
edited Nov 13 '18 at 19:29
DemShotz
asked Nov 13 '18 at 9:53
DemShotzDemShotz
32
32
update the notification every time when you want to update something in current.
– nidhi
Nov 13 '18 at 10:36
add a comment |
update the notification every time when you want to update something in current.
– nidhi
Nov 13 '18 at 10:36
update the notification every time when you want to update something in current.
– nidhi
Nov 13 '18 at 10:36
update the notification every time when you want to update something in current.
– nidhi
Nov 13 '18 at 10:36
add a comment |
2 Answers
2
active
oldest
votes
You can't change channel color notification, importance etc. programmatically without deleting the channel.
Because a user may have changed the light color manually.
To achieve this programmatically to get the channel and create a new channel with a new id. delete the old channel. Your changes will not reflect if create a channel with the previous id
for reference check WhatsApp application try to change the ringtone from an application and see in a channel at the bottom left x channel is deleted message
Source Android Doc
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
add a comment |
From createNotificationChannel() description:
This can also be used to restore a deleted channel and to update an existing channel's
* name, description, group, and/or importance.
So you can try this:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
//find created channel
NotificationChannel channel = notificationManager.getNotificationChannel("id");
if (channel != null){
//set new color
channel.setLightColor(0);
//update channel
notificationManager.createNotificationChannel(channel);
}
This throws an error because getNotificationChannel turns null on first run. I just put thegetNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if theif
ran, and it does. The color change doesn't apply though.
– DemShotz
Nov 13 '18 at 19:24
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%2f53278255%2fnotification-channel-is-it-possible-to-change-lightcolor-after-its-been-set%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't change channel color notification, importance etc. programmatically without deleting the channel.
Because a user may have changed the light color manually.
To achieve this programmatically to get the channel and create a new channel with a new id. delete the old channel. Your changes will not reflect if create a channel with the previous id
for reference check WhatsApp application try to change the ringtone from an application and see in a channel at the bottom left x channel is deleted message
Source Android Doc
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
add a comment |
You can't change channel color notification, importance etc. programmatically without deleting the channel.
Because a user may have changed the light color manually.
To achieve this programmatically to get the channel and create a new channel with a new id. delete the old channel. Your changes will not reflect if create a channel with the previous id
for reference check WhatsApp application try to change the ringtone from an application and see in a channel at the bottom left x channel is deleted message
Source Android Doc
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
add a comment |
You can't change channel color notification, importance etc. programmatically without deleting the channel.
Because a user may have changed the light color manually.
To achieve this programmatically to get the channel and create a new channel with a new id. delete the old channel. Your changes will not reflect if create a channel with the previous id
for reference check WhatsApp application try to change the ringtone from an application and see in a channel at the bottom left x channel is deleted message
Source Android Doc
You can't change channel color notification, importance etc. programmatically without deleting the channel.
Because a user may have changed the light color manually.
To achieve this programmatically to get the channel and create a new channel with a new id. delete the old channel. Your changes will not reflect if create a channel with the previous id
for reference check WhatsApp application try to change the ringtone from an application and see in a channel at the bottom left x channel is deleted message
Source Android Doc
answered Nov 13 '18 at 19:34
JarvisJarvis
64411020
64411020
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
add a comment |
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
Yeah, this is it. I thought there might have been another way. Thanks.
– DemShotz
Nov 13 '18 at 21:04
add a comment |
From createNotificationChannel() description:
This can also be used to restore a deleted channel and to update an existing channel's
* name, description, group, and/or importance.
So you can try this:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
//find created channel
NotificationChannel channel = notificationManager.getNotificationChannel("id");
if (channel != null){
//set new color
channel.setLightColor(0);
//update channel
notificationManager.createNotificationChannel(channel);
}
This throws an error because getNotificationChannel turns null on first run. I just put thegetNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if theif
ran, and it does. The color change doesn't apply though.
– DemShotz
Nov 13 '18 at 19:24
add a comment |
From createNotificationChannel() description:
This can also be used to restore a deleted channel and to update an existing channel's
* name, description, group, and/or importance.
So you can try this:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
//find created channel
NotificationChannel channel = notificationManager.getNotificationChannel("id");
if (channel != null){
//set new color
channel.setLightColor(0);
//update channel
notificationManager.createNotificationChannel(channel);
}
This throws an error because getNotificationChannel turns null on first run. I just put thegetNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if theif
ran, and it does. The color change doesn't apply though.
– DemShotz
Nov 13 '18 at 19:24
add a comment |
From createNotificationChannel() description:
This can also be used to restore a deleted channel and to update an existing channel's
* name, description, group, and/or importance.
So you can try this:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
//find created channel
NotificationChannel channel = notificationManager.getNotificationChannel("id");
if (channel != null){
//set new color
channel.setLightColor(0);
//update channel
notificationManager.createNotificationChannel(channel);
}
From createNotificationChannel() description:
This can also be used to restore a deleted channel and to update an existing channel's
* name, description, group, and/or importance.
So you can try this:
NotificationManager notificationManager = getSystemService(NotificationManager.class);
//find created channel
NotificationChannel channel = notificationManager.getNotificationChannel("id");
if (channel != null){
//set new color
channel.setLightColor(0);
//update channel
notificationManager.createNotificationChannel(channel);
}
answered Nov 13 '18 at 10:33
OnixOnix
4378
4378
This throws an error because getNotificationChannel turns null on first run. I just put thegetNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if theif
ran, and it does. The color change doesn't apply though.
– DemShotz
Nov 13 '18 at 19:24
add a comment |
This throws an error because getNotificationChannel turns null on first run. I just put thegetNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if theif
ran, and it does. The color change doesn't apply though.
– DemShotz
Nov 13 '18 at 19:24
This throws an error because getNotificationChannel turns null on first run. I just put the
getNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if the if
ran, and it does. The color change doesn't apply though.– DemShotz
Nov 13 '18 at 19:24
This throws an error because getNotificationChannel turns null on first run. I just put the
getNotificationChannel(CHANNEL_ID)
inside the if and it ran. However this doesn't work anyways. There's a sys.out in the if so I can tell if the if
ran, and it does. The color change doesn't apply though.– DemShotz
Nov 13 '18 at 19:24
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%2f53278255%2fnotification-channel-is-it-possible-to-change-lightcolor-after-its-been-set%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
update the notification every time when you want to update something in current.
– nidhi
Nov 13 '18 at 10:36