Saw this while browsing through the documentation inside android studio
Read only list of the service components that the current user has
explicitly allowed to see all of the user's notifications, separated
by ':'.
@hide
@deprecated Use
{@link NotificationManager#isNotificationListenerAccessGranted(ComponentName)}.
@Deprecated
@UnsupportedAppUsage
@Readable
public static final String ENABLED_NOTIFICATION_LISTENERS = "enabled_notification_listeners";
Hence made this up and added to a publicly accessible class
private fun notificationAccess(context: Context): Boolean {
val mNotificationManager =
context.getSystemService(NotificationListenerService.NOTIFICATION_SERVICE) as NotificationManager?;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Log.d(TAG, "notificationAccess: >27 ")
val status=mNotificationManager?.isNotificationListenerAccessGranted(
ComponentName(
context,
NotificationService::class.java
)
)
return status == true
} else {
Log.d(TAG, "notificationAccess: LESS THAN 27")
try {
val contentResolver = context.contentResolver
val listeners =
Settings.Secure.getString(contentResolver, "enabled_notification_listeners")
return !(listeners == null || !listeners.contains(BuildConfig.APPLICATION_ID))
} catch (e: Exception) {
if (DEBUG) e.printStackTrace()
}
}
return false
}
I have tested for above API above 27 , test it for below 27 before you go to production