Goal: I need open Notification Access settings to Enable/Disable read notifications by user.
Problem: Sometimes app is not in the list. For example: App is in the list after install debug build variant, but if I enable and disable Notification Access and next re-open Notification Access app is not in the list. I cannot enable it again. When device is rebooted, app is still not in the list. Sometimes app is not in the list immediately after installation debug build variant. Sometimes is or is not in the list after installation from Google Play.
How does Notification Access list work?
Docs: https://developer.android.com/reference/android/service/notification/NotificationListenerService
Register service with permission in Manifest:
<application
...
<service
android:name=".service.NotificationListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
Call Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS from Activity (only testing):
//Test:
fun onCreate() {
handler.postDelayed(()-> {
startActivityForResult(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS), 123);
}, 3000);
}
Service class:
public class NotificationListener extends NotificationListenerService {
...
}