80

I have Android Marshmallow on a Nexus 6. I am trying to fix the following problem:

If a user is trying to grant permission while a notification is showing, a "Screen overlay detected" message gets displayed and the Request Permission dialog disappears - of course the app does not get the requested permission. (Check screenshot)

I tried to fix the problem by adding "DRAW OVER OTHER APPS" permission - android.permission.SYSTEM_ALERT_WINDOW to the manifest but with no luck.

PS: I am sure the problem is caused by the notification. I do not have any app installed that overlays over other apps, I even turned off all apps with "Draw over other apps" permission in the settings. Did not help..

Anyone knows a solution to that problem?

enter image description here

Alexi Akl
  • 1,934
  • 1
  • 21
  • 20
  • see https://android.stackexchange.com/questions/126798/screen-overlay-detected-dialog – Kirill Feb 17 '16 at 10:23
  • @gsgsgs I do not have any app that overlays over other apps. Anyway I turned off all apps with "Draw over other apps" permission in the settings. Did not help. As I mentioned in the question, the problem is caused by the notification, not by an app. – Alexi Akl Feb 17 '16 at 11:56
  • 2
    This isn't really something for you to 'fix' in the code. It's a bug in Android (or at best, a poorly thought-out error message) and Google should hopefully fix it in a future release. – Learn OpenGL ES Apr 06 '16 at 20:19
  • @LearnOpenGLES I think you're right. – Alexi Akl Apr 07 '16 at 05:31
  • 3
    Happens to me when facebook messenger is open(in background) – Tim Jun 02 '16 at 13:26
  • This warning is coming because some app is running as screen overlay and might be not visible to you just like apps which shows drawers in arc styles on swipe on screen corners on bottom left or bottom right. Just click on open settings and choose enabled, it will shows all apps having overlay permission, but you just need to find which one is currently running. select that app and disable overlay permission and allow permission in your original app. if you really need to run the app which has overlay then you can enable overlay for it. The problem is only when you install the apps. – Vikas Patidar Aug 30 '16 at 05:17
  • 1
    This will also happen if a toast is showing. – GLee Oct 27 '16 at 02:19
  • I was searching for a solution while the app was working fine on all other devices except Nexus, sort of thought like a dumb person and restarted the device and that fixed the issue for me :) – shadygoneinsane Apr 25 '17 at 07:49
  • This is an issue in Android M. There might be an application service trying to draw over app for which it always show this dialog prompt. In that case, find out the application and force close or uninstall (in case force close doesn't works). This cannot he handled in code. – Rahul Raina Jul 09 '18 at 06:20

13 Answers13

74

In the circumstance that I ran across, I was causing the problem myself. It was the result of using a Toast to display information to the user at the same time that I was asking for permission. Both of these actions together cause this type of error.

The other answers might resolve someone else's issue. But I wanted to note that you should be cautious of causing your own overlays errors. Be careful of overlaying something in the view while simultaneously asking for permission.

Jay Snayder
  • 4,298
  • 4
  • 27
  • 53
8

Uninstall Clean Master app. I uninstalled it and problem solved

Hojjat
  • 815
  • 1
  • 10
  • 25
5

This problem appear because of some culprit application like Twilight, cleaner-master, drupe etc..

To solve this problem you have to disable screen overlay for those culprit apps.

i have moto g4 plus, and this is how i solve this problem

Go to Setting --> Select Apps ---> again select setting icon in Apps ---> select draw over other apps ---> and disable culprit apps who trouble for other apps.

what i done is checking each apps by disabling this permission and try to run my app, and i found one app this troubling overlay for other apps, so at the end i disabled only this app.

ScreenShots:

Select Apps select configure setting

select draw over other appsdisable culprit apps

Sagar Chavada
  • 5,169
  • 7
  • 40
  • 67
3

Got insights from multiple answers here and other forums .

Consolidating how I got rid of the issue :

  1. Go to Settings > Apps > (your app which is getting issue)
  2. Press on Power button till window for Power off , reboot , airplane mode comes up
  3. Hold on Power off option
  4. Select reboot in Safe mode
  5. Go to settings > apps > (your app which is getting issue)
  6. Select whichever permissions you want
  7. After Android M update , issues can come up in apps like Messenger , Whatsapp , Prisma etc.

Let me know if any issues .

Note : I am having One plus One mobile.

user3251882
  • 922
  • 1
  • 11
  • 21
2

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 :

Normal permission - do nothing with them, just declare in the Manifest

Vulnerable permissions - declare in Manifest and ask for permission at first time. They can be changed through system settings.

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 and if you not do that you will get exception like

Unable to add window android.view.ViewRootImpl$W@1de28ad -- permission denied for this window type

1-Request this permission by yourself in your code just like given below:

public class MainActivity extends AppCompatActivity {

public final static int REQUEST_CODE = 10000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (checkDrawOverlayPermission()) {
          Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
    }
}

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;
    }
}

@Override
@TargetApi(Build.VERSION_CODES.M)
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE) {
        if (Settings.canDrawOverlays(this)) {
              Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show();
        }
    }
}
Ghulam Qadir
  • 471
  • 3
  • 12
1

I just deleted my app and turned off my Nexus 6P. After turning it back on, I reinstalled the app and no longer got the "screen overlay" dialogs when giving the app permissions.

College Student
  • 1,719
  • 16
  • 15
  • 1
    This is closer to a comment than an answer. You could expand a bit why this works. [How to Answer](http://stackoverflow.com/help/how-to-answer) – AgataB Sep 10 '16 at 15:38
  • 1
    @AgataB I'm new to StackOverflow. I didn't have the rights to comment at the time and I didn't know why turning off the phone and uninstalling the app worked, I just thought it might help. – College Student Sep 11 '16 at 23:29
0

You must disable the overlay for all the apps you see in the list. Only this way can you modify authorizations in the app you need. I've done that in safe mode, and it worked. At the end I rebooted the phone and now it is working fine.

david_p
  • 5,722
  • 1
  • 32
  • 26
0

I updated my Sony Xperia Z3 (Dual Sim) to Android 6.0.1 (Marsmallow). I have been having screen overlay issues. For me i do not have Clean Master, Du Speed, or Du Booster(as the solutions i have read).

So i solved mine looking for any screen overlay apps.

A screen overlap app, is an app that you can use to access other apps on your main home screen without leaving your home screen. So for me the Screen Overlay App here in my situation was the OMNI SWIPE. So if you are facing this problem you need to calm down and check which of your app fits the definition of a screen overlay app.

locate the app and uninstall then restart your phone ..

i just finished doing this and am having a good time with the phone

Best of Luck

0

As long as Android 6.x is buggy on some devices where this "overlay alert" is displayed without any reason (on 2 to 5% of the devices according to my analytics data), the best solution is to avoid the whole permission process by defining the targetSdk to 22.

Take care that you can't downgrade the target sdk for a new version or this will induce a INSTALL_FAILED_PERMISSION_DOWNGRADE error when the user updates requiring an unisntall/install of the app.

toto_tata
  • 14,526
  • 27
  • 108
  • 198
0

solution is

remove Toast messages from onRequestPermissionsResult method

saigopi.me
  • 14,011
  • 2
  • 83
  • 54
0

This happens when you have granted overlay permission to malicious apps. Go to overlay settings and disable the overlay feature on all apps that don't belong to google and you will be good to go.

Gordon developer
  • 387
  • 3
  • 13
-1

I got this problem when installing a new app. The way I got around this problem is to manually enable the permissions for the newly installed app (before running the app). I’m pretty sure this is a problem with Android and Samsung devices in particular. Hope this helps

user2288580
  • 2,210
  • 23
  • 16
-4
  1. Delete the apps which have screen overlay like CM security, Clean Master, etc.

  2. Even delete and try with Messenger (FB app) if needed.