4

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.

JonasOliveira
  • 694
  • 8
  • 26

3 Answers3

9

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.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Thanks! I also saw on documentation that related to setLockscreenVisibility, seems that it is not possible to be changed by application, the documentation states: "Only modifiable by the system and notification ranker." Do you know anything about it? – JonasOliveira Nov 30 '17 at 15:26
  • 2
    Only the name and description are editable after a channel's creation, hence the note on every other field, `setLockscreenVisibility` included. – ianhanniballake Nov 30 '17 at 16:19
  • 4
    `setLockscreenVisibility` has no effect for me, even after uninstalling the app. – Florian Walther May 04 '18 at 12:28
  • Same as what @FlorianWalther said. Only works for me if I manually set the visibility for each notification manually. (e.g. NotificationCompat.Builder#setVisibility(Notification.VISIBILITY_SECRET) – avelyne Aug 01 '18 at 16:24
5

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

Will Newton
  • 51
  • 1
  • 4
  • Thanks, it was driving me nuts. In an emulator, I had to enable developer options, prevent 'stay awake' as well. – Mendhak Jul 17 '22 at 10:51
1

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.

SergeyT
  • 800
  • 8
  • 15