On Android L, I would like show the user a notification on the lock screen only if the user settings is set to "show all notification content", otherwise the content will be pointless and I just prefer not to show the notification at all.
Any idea how to verify in code the user notification settings?
Thanks!
You need to read
only if both are 1 then you need to show your notifications. But since these values are not part of public api, these might change in future, or might not work on all devices
You can't check that setting as far as I know, but your app can control the level of detail visible when its notifications are displayed over the secure lock screen. To control the visibility level, call
setVisibility()
(Notification.Builder.setVisibility
) and specify one of these values:VISIBILITY_PUBLIC
: Shows the notification’s full content.VISIBILITY_PRIVATE
: Shows basic information, such as the notification’s icon, but hides the notification’s full content.VISIBILITY_SECRET
: Shows nothing, excluding even the notification’s icon.When the visibility level is
VISIBILITY_PRIVATE
, you can also provide a redacted version of the notification content that hides personal details. For example, an SMS app might display a notification that shows "You have 3 new text messages" but hides the message content and senders. To provide this alternative notification, first create the replacement notification usingNotification.Builder
. When you create the private notification object, attach the replacement notification to it through thesetPublicVersion()
method.Sources