Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 412
Ronny Avatar asked Jan 04 '15 17:01

Ronny


People also ask

How do I show activity on lock screen instead of notification?

It's advised to use NotificationManager. IMPORTANCE_HIGH for increasing the chances of the notification appearing as a heads up notification. We also change the lockscreenVisibility to Notification. VISIBILITY_PUBLIC to tell Android that the notification can be shown on the lock screen.

How do I remove the notification bar from the lock screen Realme?

Open the first setting menu for this feature. Click on Notification and Status Bar option. There will be an option to allow notification and status bar on lock screen.


1 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"

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
}
like image 168
nandeesh Avatar answered Nov 16 '22 23:11

nandeesh