2

I have created an app which continuously run in background and show an floating overlay TextView(By using the permission android.permission.SYSTEM_ALERT_WINDOW).

I have problem in Lenovo android devices, when other applications try to request for user permission there is an alert dialog says "Screen Overlay Detected". While I have test the same application on Redmi 3S Prime device the "Allow" button in permission dialog is not clickable, until I have turned off the Floating Overlay TextView in my application.

So is there any solution to resolve this device specific issue? One of the possible solution may be disable floating TextView while permission dialog is visible to user and show floating overlay when permission dialog is closed, but the problem is how can I detect the permission dialog open/close state for other foreground application from my app.

Please suggest...

Himanshu Mohta
  • 1,033
  • 9
  • 15

5 Answers5

4

Unfortunately it seems that this is inherent to the Android OS, and as far as I know there is no way to detect when another app is requesting permissions. The general flow for interacting with other apps is to send intents to them in a push manner, so theoretically it could be done if the other apps send an intent to your app to disable the overlay, though this is not a practical solution.

I could be completely wrong, but I am yet to see a programmatic solution to this problem. The best you can probably do is warn your users that your app may cause this problem, and provide them with a quick temporary disable button.

Lukeyb
  • 807
  • 6
  • 24
  • I have seen an app on google play which does the same. The app name is Network Monitor Mini, but I am not sure how to handle this – Himanshu Mohta Jun 29 '17 at 05:22
2

how can I detect the permission dialog open/close state from my app??

  • Implement Method Mentioned Below, to run this check at the onCreate of the first Activity

    public final static int PERM_REQUEST_CODE_DRAW_OVERLAYS = 1234;

/** * Permission to draw Overlays/On Other Apps, related to

'android.permission.SYSTEM_ALERT_WINDOW'

in Manifest

  • Resolves issue of popup in Android M and above "Screen overlay detected- To change this permission setting you first have to turn off the screen overlay from Settings > Apps"
    • If app has not been granted permission to draw on the screen, create an Intent &
    • set its destination to

Settings.ACTION_MANAGE_OVERLAY_PERMISSION

& * add a URI in the form of

"package:"

to send users directly to your app's page.

Note: Alternative Ignore URI to send user to the full list of apps.

 public void permissionToDrawOverlays() {
        if (android.os.Build.VERSION.SDK_INT >= 23) {   //Android M Or Over
            if (!Settings.canDrawOverlays(this)) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, PERM_REQUEST_CODE_DRAW_OVERLAYS);
            }
        }
    }

Called on the activity, to check on the results returned of the user action within the settings

 @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PERM_REQUEST_CODE_DRAW_OVERLAYS) {
          if (android.os.Build.VERSION.SDK_INT >= 23) {   //Android M Or Over
                if (!Settings.canDrawOverlays(this)) {
                    // ADD UI FOR USER TO KNOW THAT UI for SYSTEM_ALERT_WINDOW permission was not granted earlier...
                }
            }
        }
          }

NOTE:Above code and extract is taken from following gist.

Hope this Helps!!!..

PN10
  • 1,888
  • 3
  • 23
  • 34
  • Actually I wants to detect the permission dialogue open/close status for other apps, not for my app. I wants to remove floting window in my app if other apps try to request for a permission, and add floating window again if permission dialogue of other app get closed – Himanshu Mohta Jun 29 '17 at 14:37
  • @HimanshuMohta U hav edited ur orignal question earlier it was not such ...anyway how can other apps give u permission to change their status... it will be kind of security risk..to other apps if they allow you to do anything like that so i don't think it will be practically possible....anyhow... – PN10 Jun 30 '17 at 07:48
  • I have edited because there is some misunderstanding. Also it is possible because an app on google play does the same.The app name is Network Monitor Mini – Himanshu Mohta Jun 30 '17 at 09:39
2

Just clear data of the Es explorer from device then after restart device.

Sachin Suthar
  • 692
  • 10
  • 28
1

I think these two links could help you. firstlink secondlink

susaine
  • 141
  • 1
  • 9
0

Try to use for debug build -- targetSdkVersion 22.

After signed APK (for all targetSdkVersion(s)) application will work fine.