SYSTEM_ALERT_WINDOW - how to get this permission automatically on Android 6.0 and targetSdkVersion 23

Facebook, Evernote, Pocket - all applications receive this permission on Android 6.0 automatically, even if they are aimed at 23 ( targetSdkVersion=23 ).

There was a lot of documentation regarding the new Marshmallow resolution model. One of them, SYSTEM_ALERT_WINDOW was “advanced” to “above the dangerous” permission class, which requires special user intervention in order for applications to be provided to them. If the application has targetSdkVersion 22 or lower, the application automatically obtains this permission (if required in the manifest).

However, I noticed some applications that received this permission, without having to send the user to a special settings page Draw over other apps . I saw Facebook, Evernote, Pocket - and possibly more.

Does anyone know how an application can get this permission without user intervention Settings -> Apps -> Draw over other apps ?

thank

+46
android android-6.0-marshmallow android-permissions target-sdk system-alert-window
Mar 15 '16 at 16:03
source share
3 answers

This is a new behavior introduced in Marshmallow 6.0.1 .

Each application that requests SYSTEM_ALERT_WINDOW permission and is installed through the Play Store (version 6.0.5 or higher is required) will automatically grant permission.

If instead the application loads, permission is not automatically granted. You can try downloading and installing the Evernote APK from apkmirror.com . As you can see, you need to grant permission to use manually in Settings -> Apps -> Draw over other apps .

These are the commits [1] [2] that allow the Play Store to automatically grant SYSTEM_ALERT_WINDOW permission.

+73
Mar 15 '16 at 18:14
source share

yeh After the release of Marshmallow, Android will make the security level more stick, but for

 SYSTEM_ALERT_WINDOW 

you can show a floating action and all that you can get the user to give permission to it. Following the codes in your Oncreate () method Put this code after setContentView

 / // Check if Android M or higher if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ // Show alert dialog to the user saying a separate permission is needed // Launch the settings activity if the user prefers Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); startActivity(myIntent); } 

The ACTION_MANAGE_OVERLAY_PERMISSION action directly launches the "Draw on other applications" permission screen.




Edit

Hi my above code is working 100% Correct

but I just found that many guys are still looking for how to enable ACTION_MANAGE_OVERLAY_PERMISSION for a long time, as if the user has allowed permission. After that, do not ask him every time he opens the application , so listen to the solution for you- 1) Check that the device has api 23+

2) if 23+ api then check if user is allowed or not

3) if he allowed once not to deliver it to Settings.ACTION_MANAGE_OVERLAY_PERMISSION, and if he hasn’t yet, ask him to check the permission at run time

  Put below line in in your Oncreate() method Put this after setContentView checkPermission(); 

Now put below code in onActivityResult

  @TargetApi(Build.VERSION_CODES.M) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE) { if (!Settings.canDrawOverlays(this)) { // You don't have permission checkPermission(); } else { //do as per your logic } } } 

Now, finally, the code of the checkPermission method

 public void checkPermission() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE); } } } 

and don't forget to declare this public variable in your class

 public static int ACTION_MANAGE_OVERLAY_PERMISSION_REQUEST_CODE= 5469; 

greetings !; -)

+27
Sep 09 '16 at 8:03
source share

If the application is intended for API 22 or lower, then the Play Store will grant SYSTEM_ALERT_WINDOW and others permissions when the user clicks on the installation (showing a warning), even if his device is Android 6.0 Otherwise, if the application is intended for API 23 or higher, so the permission will be requested at runtime.

0
Apr 07 '16 at 21:05
source share



All Articles