99

Facebook, Evernote, Pocket - all apps get this permission on Android 6.0 automatically, even though they are targeting 23 (targetSdkVersion=23).

There has been a lot of documentation regarding the new Marshmallow permission model. One of them is SYSTEM_ALERT_WINDOW been 'promoted' to 'above dangerous' permission class thus requiring a special user intervention in order for apps to be granted with those. If the app has targetSdkVersion 22 or lower, app gets this permission automatically (if requested in the manifest).

However, I've noticed some apps that get this permission, without needing to send the user to the setting special page of Draw over other apps permission. I saw Facebook, Evernote, Pocket - and perhaps there are more.

Anyone knows how an app can be granted this permission without the user go through Settings -> Apps -> Draw over other apps?

Thanks

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
oriharel
  • 10,418
  • 14
  • 48
  • 57
  • http://stackoverflow.com/questions/33139754/android-6-0-marshmallow-cannot-write-to-sd-card this helped me – Bharath Jan 26 '17 at 07:06
  • http://stackoverflow.com/questions/33139754/android-6-0-marshmallow-cannot-write-to-sd-card this post helped me to show dialog permission of write to external – Bharath Jan 26 '17 at 07:08
  • 1
    Update 2020: https://stackoverflow.com/a/60005258/4720433 – Kzaf Jan 31 '20 at 13:57

5 Answers5

123

It is a new behaviour introduced in Marshmallow 6.0.1.

Every app that requests the SYSTEM_ALERT_WINDOW permission and that is installed through the Play Store (version 6.0.5 or higher is required), will have granted the permission automatically.

If instead the app is sideloaded, the permission is not automatically granted. You can try to download and install the Evernote APK from apkmirror.com. As you can see you need to manually grant the permission in Settings -> Apps -> Draw over other apps.

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

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
  • 7
    Although I wonder how come an 'above dangerous' permission suddenly is now 'below normal'. I mean, you don't even get to see this permission in a popup, and apps can get it automatically. Any thoughts? – oriharel Mar 16 '16 at 07:56
  • The permission remains `above dangerous` in fact if you sideload the app the permission is not granted. It is only the Play Store that has a different behaviour and grants automatically the permission, maybe they thought that the apps on the play store are not malicious and they can be trusted. Or maybe they received a lot of complaints about this change and they decided to find a workaround. – Mattia Maestrini Mar 16 '16 at 09:23
  • 3
    @oriharel I wonder if the massive scale of Facebook Messenger nudged Google in this direction to support this. Could've been that Facebook struck a deal w/ Google to not force the user to grant the permission so that chatheads could continue working. – dennisdrew Aug 04 '16 at 22:02
  • @MattiaMaestrini So what steps shall we take if we are targeting older versions of Android (4+) to grant this permission? – Ashraf Alshahawy Aug 11 '16 at 22:01
  • 3
    When I asked about this behavior of auto-granting this permission (I thought the reason is something else : the targetSdk) the response of Google was "This is an intended behavior to allow popular apps to keep working until we have an alternative APIs in the platform for these apps to migrate." . Here're the posts: https://code.google.com/p/android/issues/detail?id=227123 https://code.google.com/p/android/issues/detail?id=222195 – android developer Jan 02 '17 at 13:00
  • Permission is automatically granted, but System Overlay Detected Problem is not solved in any way which is what we need to do. – Rakesh Yadav Mar 14 '17 at 05:51
  • I just sideloaded 9Apps & vidmate and draw over other apps was automatically granted to them. Any clue how ? – Gautam Mar 30 '17 at 06:03
  • @Gautam The `targetSdkVersion` of Vidmate is 17 and the `targetSdkVersion` of 9Apps is 20. These rules applies only to the apps that target 23, otherwise the permission is granted automatically as described in the question. – Mattia Maestrini Mar 30 '17 at 10:31
  • The answer below by Jayman Jani is the correct one. On android M and above (API 23), you need to explicitly send an intent as he shows to request this permission (this is different from most other "dangerous) permissions"). For API revs less than 23, the permission is granted at install time. – Rob Jun 25 '17 at 15:40
  • 1
    @MattiaMaestrini can you have a look at this similar question? https://stackoverflow.com/questions/54378632/draw-overlay-permisssion-for-apps-installed-from-play-store – ram Jan 27 '19 at 13:25
98

Yeh After Marshmallow come Android make security level more stick, But For SYSTEM_ALERT_WINDOW you can show floating action and anything You can Force user to give permission for it By Following 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 ACTION_MANAGE_OVERLAY_PERMISSION directly launches the 'Draw over other apps' permission screen.


Edit:

My Above Code works 100% Correct

But I just found that many guys are still searching that how can allow ACTION_MANAGE_OVERLAY_PERMISSION permanently like If user has allow Permission Once then don't ask it every time he open application so here is a solution for you:

  1. Check if device has API 23+

  2. if 23+ API then check if user has permit or not

  3. if had permit once don't drive him to Settings.ACTION_MANAGE_OVERLAY_PERMISSION and if has not permit yet then ask for runtime permission check

Put below line 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 checkPermission method code:

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;
juzraai
  • 5,693
  • 8
  • 33
  • 47
Jayman Jani
  • 1,251
  • 10
  • 15
18

Now(2019) that Google offers an alternative API to SYSTEM_ALERT_WINDOW in the form of Bubbles in Android Q, Google has decided to eventually deprecate SYSTEM_ALERT_WINDOW in a future Android release.

And Android Go devices will no longer grant this permission i.e Settings.canDrawOverlays() == false

  • how do you know this? The documentation says it's still in preview. https://developer.android.com/guide/topics/ui/bubbles – Noa Drach Jan 15 '20 at 08:39
  • 1
    True @NoaDrach , that's why I said in the future Google will eventually deprecate SAW - i.e when Bubble API is stable. https://youtu.be/td3Kd7fOROw?t=136 – Dickson the developer Jan 15 '20 at 14:11
  • thanks, I was asking b/c my app(that isn't targeting Q yet), used to receive this permission automatically when installed from the play store , and now we don't get it automatically . I guess it's b/c of this - https://www.reddit.com/r/androiddev/comments/a69q0i/question_did_the_play_store_stop_auto_granting/ – Noa Drach Jan 15 '20 at 16:34
  • @Dicksonthedeveloper Please let me how to identify the which device don't have feature of SYSTEM_ALERT_WINDOW or screen overlay permission i need solution of this https://stackoverflow.com/questions/63938787/how-to-check-detect-or-identify-the-settings-component-screen-overlay-or-any-fe – Shaikh Mohib Sep 17 '20 at 13:33
  • Android 11 contains this API – NothingtoSay Oct 19 '20 at 11:45
  • @Dicksonthedeveloper Do you have any content to support your claim of "Google will eventually deprecate SAW" I'm building a ride hailing app and I would want to know wether I should go this route or use fullScreenIntent Thanks – Mohsin Falak Sep 23 '22 at 14:13
17

For those who want to get this permission automatically when the app is downloaded from the Play Store, besides the SYSTEM_ALERT_WINDOW in the Manifest, you should go to this link and request this from Google.

You have to provide some additional information why you need this permission and Google will review and give you the automatically permission.

Bear in mind that before you ask for this, you have to:

  • Have the SYSTEM_ALERT_WINDOW permission in the Manifest

  • Prompt the user to grant the SYSTEM_ALERT_WINDOW permission within your app, when not already granted

If I miss something feel free to update the answer

Kzaf
  • 563
  • 7
  • 19
  • This must be the correct answer now. Thank you. Please just add your answer to how we can ask user for this permission programmatically. – Eren Tüfekçi Sep 23 '20 at 18:24
  • 2
    is this still valid 2021? "Your app uses an accessibility service and you need to provide an explanation documenting how the app uses the system capabilities that the service requests. " is this the scenario you are talking about? should we send a request email after we have launched our app to play store? – Samer Alkhatib Jun 07 '21 at 06:50
3

If the app targets API 22 or lower, then Play Store will give the SYSTEM_ALERT_WINDOW permission and others when the user clicks to install (showing an alert) even if its device is Android 6.0 Otherwise, if the app targets API 23 or above, so that permission will be request to grant in run time.

Dennix
  • 139
  • 1
  • 5
  • as per updated play store policy(since Aug 2018) you should not target SDK Less than 26, see this reference links 1) https://developer.android.com/distribute/best-practices/develop/target-sdk 2) https://medium.com/codespace69/google-play-warning-app-must-target-at-least-api-level-26-to-ensure-it-is-built-on-the-latest-7a8729d70679 – Jayman Jani Jun 26 '20 at 05:41