在 setLockscreenVisibility(Notification.VISIBILITY_SECRET) 之后,通知通道仍然出现在锁屏上

Jon*_*ira 4 notifications android android-notifications notification-channel

将通知频道设置为在锁屏不显示通知后,它仍然在锁屏上显示通知。

notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
notificationManager.createNotificationChannel(notificationChannel);
Run Code Online (Sandbox Code Playgroud)

但是在创建频道后我可以调试它,看到通知频道没有将lockScreenVisibility设置为VISIBILITY_SECRET(-1),它仍然具有默认值,即-1000。

notificationChannel.getLockscreenVisibility()
Run Code Online (Sandbox Code Playgroud)

有谁知道如何设置锁屏可见性不显示在锁屏上?或者知道为什么它没有被更新?

还有一个信息是我之前已经创建了频道。但是我已经使用 VISIBILITY_SECRET 删除并重新创建了频道。

ian*_*ake 7

当您删除并重新创建频道时,所有以前的设置都将恢复。如果您想更改频道名称或描述以外的任何内容,您必须创建一个全新的频道(使用不同的频道 ID)或完全卸载/重新安装该应用程序。

  • `setLockscreenVisibility` 对我没有任何影响,即使在卸载应用程序后也是如此。 (4认同)
  • 在频道创建后,只有名称和描述是可编辑的,因此每个其他字段的注释,包括“setLockscreenVisibility”。 (2认同)

小智 5

发生这种情况的原因可能是,如果锁定屏幕不安全(例如未设置 PIN),即使是秘密通知也会显示在锁定屏幕上:

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