Skip to content

Instantly share code, notes, and snippets.

@romellfudi romellfudi/
Last active Jul 14, 2019

What would you like to do?

This popup is caused by the manifest.PERMISSION.SYSTEM_ALERT_WINDOW permission declared by the manifest. The are 3 categories of permissions, that developer must be aware of.:

  1. Normal permission - do nothing with them, just declare in the Manifest
  2. Vulnerable permissions - declare in Manifest and ask for permission at first time. They can be changed through system settings
  3. Above dangerous permissions: SYSTEM_ALERT_WINDOW and WRITE_SETTINGS belong to this category. They must be granted, but are not visible in system settings. To request for it you don't use a standard way (int checkSelfPermission (String permission)) but you have to check Settings.canDrawOverlays() or Settings.System.canWrite() appropriately

If you don't have SYSTEM_ALERT_WINDOW permission:

  1. check if you have a Toast visible when interacting with the permissions popup. Though the Overlay Detected popup doesn't mention it, a Toast also counts as an overlay
  2. check if any of your dependencies require it.

If you're not sure if you're using this permission, there are a couple of test cases that you can do:

  1. Request this permission by yourself:

    public class MainActivity extends AppCompatActivity {
        public final static int REQUEST_CODE = 10101;
        protected void onCreate(Bundle savedInstanceState) {
            if (checkDrawOverlayPermission()) {
                startService(new Intent(this, PowerButtonService.class));
        public boolean checkDrawOverlayPermission() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                return true;
            if (!Settings.canDrawOverlays(this)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, REQUEST_CODE);
                return false;
            } else {
                return true;
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == REQUEST_CODE) {
                if (Settings.canDrawOverlays(this)) {
                    startService(new Intent(this, PowerButtonService.class));
  2. Check if this or this is not your case

  3. Check out this post to be aware, that when installing app through Play Store this permission is automatically granted (I have not checked is, therefore cannot confirm)

The permission model can be understood, just sometimes requires more digging.

Check this question and the answer: SYSTEM_ALERT_WINDOW - How to get this permission automatically on Android 6.0 and targetSdkVersion 23 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.