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

我的未来我决定 提交于 2019-12-10 08:51:56

问题


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!


回答1:


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
}



回答2:


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



来源:https://stackoverflow.com/questions/27768345/check-android-users-when-device-is-locked-notification-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!