How can I determine programmatically if a permission dialog is visible to the user so I know what to do in this case?
The method shouldShowRequestPermissionRationale() can be used to check whether the user selected the 'never asked again' option and denied the permission.
How do you check if the current activity has a dialog in front? You can override activity method onWindowFocusChanged(boolean hasFocus) and track the state of your activity. Normally, if some alert dialog is shown above your activity, the activity does not get onPause() and onResume() events.
Permission dialog is an activity that is put on top of the activity stack. So when you call for requestPermission()
method Activity
implementation asks the PackageManager
to build intent that will start this activity dialog. This intent has ACTION_REQUEST_PERMISSIONS
action.
Probably you need to listen for activity stack changes and check if activity intent has ACTION_REQUEST_PERMISSIONS
action. I'm not sure if obtaining running tasks will give you this activity listed, because I haven't tried this myself, only to get you going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With