My app does not work without Notification Access, and I want to display a warning when it is on or off.
Is there a way I can monitor this setting without just polling it? Like is there something I can subscribe to that will automatically update me what this setting is changed?
I have tried the following code, but it is not updated when I update the setting.
var contentResolver = getContentResolver();
val setting = Settings.System.getUriFor(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
val observer: ContentObserver = object : ContentObserver(Handler(Looper.getMainLooper())) {
override fun onChange(selfChange: Boolean) {
super.onChange(selfChange)
}
override fun deliverSelfNotifications(): Boolean {
return true
}
}
contentResolver.registerContentObserver(setting, false, observer);