It completely ignores:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
So I got exception:
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@86fb55b -- permission denied for this window type
It's not even listed:
How should I fix it? Thanks.
EDIT:
It's listed in Configure apps/ Advanced / Draw over other app. So i turn it on and now it works fine, but why there isn't any dialog to ask about permission when i run my app? All perrmissions was turned off by deafult and i need to go to settings and mannualy turn it on?
Thanks to CommonsWare's blog post, I got some clue.
Assuming your code is in Activity
or Fragment
, check the overlay permission and make a request for it if necessary:
public static int OVERLAY_PERMISSION_REQ_CODE = 1234; public void someMethod() { if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); } }
Then, re-check the permission for better UX:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { if (!Settings.canDrawOverlays(this)) { // SYSTEM_ALERT_WINDOW permission not granted... } } }
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