Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom notification light color on Android 8+ #5544

Closed
cketti opened this issue Aug 7, 2021 · 17 comments · Fixed by #5828
Closed

Add support for custom notification light color on Android 8+ #5544

cketti opened this issue Aug 7, 2021 · 17 comments · Fixed by #5828
Labels
type: enhancement New features or improvements to existing features.

Comments

@cketti
Copy link
Member

cketti commented Aug 7, 2021

Android 8 has introduced notification channels where an app can only provide an initial configuration. After creation a notification channel can only be configured by the user via Android's notification settings. Unfortunately their settings screen doesn't allow setting a color for the notification light.

It seems like our only option is to use our own UI to allow users to select a color for the notification light. Then we'll have to delete the existing notification channel and create a new one (copying the configuration of the old notification channel).
We will also have to use a different ID for the new notification channel. So we have to dynamically create that ID and keep track of it instead of being able to use a static identifier.

See also #5543

@kriegste

This comment has been minimized.

@kriegste
Copy link

The options for LED notification and vibrate pattern now appear in the account settings. However, they are greyed-out, so they cannot be used. Tested on Huawei Mediapad and Ulefone (both Android 8).

@cketti
Copy link
Member Author

cketti commented Dec 30, 2021

You have to enable vibration and "blink light" for the "Messages" notification category first.

@kriegste
Copy link

Screenshot_20211230-180034

I can see vibrate, but not the more important light setting.

@cketti
Copy link
Member Author

cketti commented Dec 30, 2021

Either your device has no notification light or you'll have to enable it in Android settings.

@kriegste
Copy link

Same problem on Honor 8X. All three Devices work fine with K9 5.6 (out of the box).

@kriegste
Copy link

I wonder why those options have to be grayed out anyway. In version 5.6 they were accessible all the time and the feature just worked great.

@cketti
Copy link
Member Author

cketti commented Dec 30, 2021

If you want to learn more about how the notification API on Android works, I suggest starting here: https://developer.android.com/training/notify-user/channels

@kriegste
Copy link

kriegste commented Dec 30, 2021

Thanks. I'll go back to version 5.6 until the bug is fixed.

@kriegste
Copy link

Looks like you just have to call enableLights and setLightColor...

@cketti
Copy link
Member Author

cketti commented Dec 30, 2021

By default global use of the notification light is disabled on newer Android versions.

Your screenshot doesn't show a "blink light" option, so for you it's most likely disabled in Android settings. On one of my test devices with a notification LED (Android 8) the setting can be found under Android settings > Apps & notifications > Notifications > Blink light. It's probably best to use the search function to search for "blink light".

image

Afterwards a "Blink light" option will appear in the "Messages" notification category screen.

image

After enabling it there, you'll be able to select a notification light color in K-9 Mail.

@kriegste
Copy link

There is a global setting, yes. It is enabled (other apps can blink the LED- including K9 5.6).

By the way, my Honor 8X has Android 10. The other two devices have Android 8. Unfortunately I don't own more devices, so my testing abilities are limited. But on all 3 (of 3) devices, this problem exists. All have notification LEDs which worked fine in K9 5.6.

@kriegste
Copy link

Could you publish a debugging version of K9 which simply ignores the value returned by shouldShowLights (and assumes "true")?

@cketti
Copy link
Member Author

cketti commented Jan 1, 2022

The setting in K-9 Mail will only configure the light color, not enable the "blink light" feature. That's typically done using Android's UI to change the settings of the notification category. Allowing the user to pick a color when the feature is not enabled won't do anything.

Since you feel confident enough to suggest code changes, you should have no trouble building the app yourself. It's basically installing Android Studio, cloning the repository, and opening the project in Android Studio. See https://github.com/k9mail/k-9/wiki/BuildingK9 (somewhat outdated, but still mostly correct)

You could try removing the code to disable the notification light preference and then explicitly enable the notification light in NotificationChannelManager.recreateMessagesNotificationChannel(). That way you'll know if the notification category can be configured with "blink lights" enabled even though you don't see the option in the UI.

@kriegste
Copy link

kriegste commented Jan 3, 2022

https://github.com/k9mail/k-9/search?q=shouldshowlights

I can confirm that replacing both occurrences of shouldShowLights() by "true" resolves the issue.

k9mail-debug.zip

@cketti
Copy link
Member Author

cketti commented Jan 4, 2022

Thanks for testing this 👍

It looks like some vendors were really lazy when building their Android version and only allow the user to change very few properties of a notification. To allow users of such devices to configure the notification category, we'll have to basically offer the settings that should be available in the system UI.

I guess we can do this in one of two ways:

  1. Display the options inside the app on all devices. This will most likely lead to quite a few support request asking e.g. why the notification light can be enabled inside the app and using the system user interface.
  2. Only display the options inside the app when we know the system UI doesn't offer the option. This requires keeping track of all broken Android versions and what settings they are missing exactly.

Neither of these options sounds very appealing. I'll have to think about this for a bit.


@kriegste: Out of curiosity; does the "notification management" screen allow you to change the "ringtone" or can you only turn it on and off?

@kriegste
Copy link

kriegste commented Jan 4, 2022

On my Honor 8X (Android 10) I can change the sound per app. I will have a look into the other devices later.

Please don't complicate the issue.
I'd rather just enable the light for everyone and give it the account color. It is strange having two different color pickers.

Edit:
Huawei Mediapad M5 lite (Android 8): Ring tone cannot be changed per app. Only "on" and "off".

Edit2:
The color picker for the account color has 16 colors (pure red, green, blue and yellow missing) and the color picker for the notification light has 24 colors. That is a bit strange, too. If you ask me, just combine this all into a single color picker with those 24 colors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New features or improvements to existing features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants