CookieMonster
CookieMonster

Reputation: 1833

Find if notifications are disabled on lock screen by the user

In Android there is an option to choose how notifications will show on the lock screen:

  1. Show all notification content.
  2. Hide sensitive content.
  3. Don't show notifications at all.

In phones that run stock Android OS the lock screen preferences are global for all the apps. But in Xiaomi it is possible to configure these preferences for each app.

Is there a way I can programmatically find out from my android app if the user selected to opt out from notifications on lock screen?

enter image description here

Upvotes: 2

Views: 985

Answers (1)

rekire
rekire

Reputation: 47985

I am not sure if this works on all Android versions, but this works for me:

fun getLockscreenNotificationsEnabled(context: Context) =
    android.provider.Settings.Secure.getInt(
        context.contentResolver,
        "lock_screen_show_notifications", 0
    ) != 0

Upvotes: 1

Related Questions