Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android M detect if permission dialog is visible

How can I determine programmatically if a permission dialog is visible to the user so I know what to do in this case?

like image 848
ThanosFisherman Avatar asked Dec 12 '15 03:12

ThanosFisherman


People also ask

How can I tell if an Android user is denied permission?

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?

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.


1 Answers

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.

like image 83
Nikola Despotoski Avatar answered Sep 17 '22 15:09

Nikola Despotoski