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
  • 720
  • 7
  • 21

2 Answers2

7

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
  • 155,909
  • 19
  • 351
  • 362
  • 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
3

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