0

I have an Android app relying on notifications for certain activities. I know how to check that the notification permission has been granted as well as the specific settings of notification channels. Is there a way to check which notification types are currently allowed for the whole app (i.e., Lock screen, Badge, and Pop-up)?

This information is important since turning off a notification type for the whole app overrides the settings for a specific channel. If all three notification types are turned off, no notifications are shown yet the checkSelfPermission() call on POST_NOTIFICATIONS still returns the permission being granted since "Allow notifications" are checked, which is the problem I am having.

The specific settings can be checked on notification channels with getImportance(), and I would need some way to do a similar thing for the whole app.

The settings I need to check:

The settings I need to check.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zewa
  • 1
  • 2
  • Does anything of this fit your use case? https://stackoverflow.com/questions/30719047/android-m-check-runtime-permission-how-to-determine-if-the-user-checked-nev Generally you have to use ```PermissionChecker``` https://developer.android.com/reference/androidx/core/content/PermissionChecker – Gleichmut Aug 14 '23 at 10:39

1 Answers1

0

As of September 2021, Android does not provide a direct API to programmatically check the specific types of notifications (badge, popup, locked screen) .

But you can check locked screen notification is allowed or not by

int importance = channel.getImportance();

if (importance != NotificationManager.IMPORTANCE_NONE) {
    // Notifications are allowed
    if (importance == NotificationManager.IMPORTANCE_HIGH) {
        // High-importance notifications can show on the lock screen
    }
} else {
    // Notifications are not allowed
}

Also to solve your problem, you can always check for notification permission if it disabled in onresume of Activity or Fragment.

You'll get false here in below code then ask again or redirect user to settings screen

 override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray,
    ) {
   //write your code to request for permission or redirect user to settings screen
    }

 
Suresh Maidaragi
  • 2,173
  • 18
  • 25