mbonnin mbonnin - 1 year ago 175
Android Question

onActivityResult() is called to early for Settings.ACTION_MANAGE_OVERLAY_PERMISSION

I want to request the Overlay permission for my app to draw on top of other apps. For this I use ACTION_MANAGE_OVERLAY_PERMISSION

Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 1234);

This works well and shows the appropriate setting screen but
is called when the setting activity is first shown and not when destroyed so I never get the permission in
. Do I miss something ?

Answer Source

This is because you are starting a new task. From the documentation

[...] if the activity you are launching uses the singleTask launch mode, it will not run in your task and thus you will immediately receive a cancel result.

So it should work if you remove

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download