问题
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)
回答1:
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()));
来源:https://stackoverflow.com/questions/53930842/how-to-check-for-apps-which-has-draw-over-other-apps-as-true