简体   繁体   中英

Check Android user's “when device is locked” notification settings

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

Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS = "lock_screen_allow_private_notifications"

Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS = "lock_screen_show_notifications"

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

int show_all = Settings.Secure.getInt(getContentResolver(),"lock_screen_allow_private_notifications", -1); 
int noti_enabled = Settings.Secure.getInt(getContentResolver(),"lock_screen_show_notifications", -1); 

if(show_all > 0 && noti_enabled > 0){
//post noti
}

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 using Notification.Builder . When you create the private notification object, attach the replacement notification to it through the setPublicVersion() method.

Sources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM