Ravi Singh
Ravi Singh

Reputation: 11

How to check for apps which has Draw over other apps as True?

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)

Upvotes: 1

Views: 1932

Answers (1)

Master Fathi
Master Fathi

Reputation: 349

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()));

Upvotes: 0

Related Questions