After setLockscreenVisibility(Notification.VISIBILITY_SECRET) the notification channel is still appearing on lockscreen

7.9k Views Asked by At

After set a notification channel to not show notifications at lockscreen, it still is showing the notifications on lockscreen.

notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
notificationManager.createNotificationChannel(notificationChannel);

But after the creation of the channel I can debug it and see that the notification channel does not have the lockScreenVisibility set to VISIBILITY_SECRET (-1), it still has the default value, that is -1000.

notificationChannel.getLockscreenVisibility()

Does anyone knows how to set the lockscreen visibility to not show on lockscreen? Or have any idea why it is not being updated?

One more information is that I already have created the channel previously. But I have deleted and recreated the channel with the VISIBILITY_SECRET.

3

There are 3 best solutions below

4
On BEST ANSWER

When you delete and recreate a channel, all of the previous settings are restored. You must create a brand new channel (with a different channel ID) or completely uninstall/reinstall the app if you want to change anything other than the channel's name or description.

0
On

The documentation says that setLockscreenVisibility and setBypassDnd are "Only modifiable by the system and notification ranker."

The suggestion of @WillNewton works only after you have manually changed this settings.

1
On

The reason this may be happening is that even secret notifications are show on the lock screen if the lock screen is not secure (e.g. a PIN is not set):

https://android.googlesource.com/platform/frameworks/base/+/android-8.1.0_r33/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java#521