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

二次信任 提交于 2020-01-05 07:12:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!