I am trying to provide Notification Access to my app, for that I have added below permission in Manifest
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
Also I have registered listener as below on activity.
IntentFilter notlist = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
notlist = new IntentFilter(ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED);
}
Intent notlistch = registerReceiver(null,notlist);
Now when user clicks on button I have below code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
startActivity(new Intent(ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS));
}
Now If I click on button with above code in it, this will always take me to notification settings, so if my app has got access during first click, how can I check it before throwing intent for opening settings.
I read to use ACTION_NOTIFICATION_POLICY_ACCESS_GRANTED_CHANGED
, but did not understand how to use it. Can anyone help me.
ideally I should check access status first and then on getting false, I should call intent to open notification settings.