Check Android users "when the device is locked." Notification settings

On Android L, I would like to show the user a notification on the lock screen only if the user’s settings are set to “show all notification content”, otherwise the content will be meaningless, and I just prefer not to show the notification at all.

Any idea how to check custom notification settings in the code?

Thank!

+4
source share
2 answers

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"

1, . public api, .

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
}
+2

, , , , . , setVisibility() (Notification.Builder.setVisibility) :

VISIBILITY_PUBLIC: .

VISIBILITY_PRIVATE: , ​​ , .

VISIBILITY_SECRET: , .

VISIBILITY_PRIVATE, , . , SMS , " 3 ", . , , Notification.Builder. , setPublicVersion().

+1

Source: https://habr.com/ru/post/1569903/


All Articles