1

I am a bit puzzled over getting active system alert window permissions for a package in Android. I am using the code below, but this code returns 0 even if we disallow that app from "Draw over other app". Any Pointers?.

My use case is to have a check in place where if any app with system_alert_window permission is found, we need to tell user to change that apps permission to proceed further.

packageManager.checkPermission("android.permission.SYSTEM_ALERT_WINDOW", info.packageName)

Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
Ravi Singh
  • 11
  • 3

1 Answers1

0

I created this method to check if the permission is given or not

public static boolean checkDrawOverlayPermission(Context context) {
        /** check if we already  have permission to draw over other apps */
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return Settings.canDrawOverlays(context);
        }
        return true;
    }

You can after that, if you want to guide the user to the place where he can enable that option do :

Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + activity.getPackageName()));
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
Master Fathi
  • 349
  • 1
  • 9
  • 19
  • 2
    Thanks for your response, May be I was not clear, i want to check if there is any existing app on users device before allowing users to use my app completely, else display them list of apps that have system_alert_window and how they can disable there system_alert_window permission rather then uninstalling those apps. – Ravi Singh Dec 26 '18 at 16:30
  • any solution for this problem. – DAC84 Apr 05 '22 at 12:02