Android M detects a permission dialog is displayed

How can I determine programmatically if permission windows are visible to the user, so I know what to do in this case?

+6
source share
2 answers
@Override protected void onStart() { super.onStart(); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); ComponentName cn = am.getRunningTasks(1).get(0).topActivity; if ("com.android.packageinstaller.permission.ui.GrantPermissionsActivity".equals(cn.getClassName())){ //permission dialog is displayed } }` 

`

0
source

The Permission dialog box is an action that is placed on top of the activity stack. Therefore, when you call the requestPermission() method of the Activity method, the implementation requests the PackageManager to create an intent that will trigger this activity dialog. This intent has an ACTION_REQUEST_PERMISSIONS action .

You might need to listen to the changes in the activity stack and check if the activity has an ACTION_REQUEST_PERMISSIONS activity. I'm not sure that getting started tasks will give you this activity, because I did not try it myself, just to let you go.

+1
source

All Articles