Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission from manifest doesn't work in Android 6

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:

enter image description here

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?

like image 226
Djordje Tankosic Avatar asked Aug 18 '15 00:08

Djordje Tankosic


1 Answers

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...         }     } } 
like image 148
Shigerello Avatar answered Oct 01 '22 11:10

Shigerello