Fatal Exception: java.lang.NoSuchMethodError: No static method canDrawOverlays(Landroid/content/Cont

1、问题抛出:

Fatal Exception: java.lang.NoSuchMethodError: No static method canDrawOverlays(Landroid/content/Context;)Z in class Landroid/provider/Settings; or its super classes (declaration of 'android.provider.Settings' appears in /system/framework/framework.jar)

我们知道API 23以前,可以在其他app上绘制内容不需要权限申请或者其他操作, API 23及23之后需要申请

SYSTEM_ALERT_WINDOW权限以及ACTION_MANAGE_OVERLAY_PERMISSION

提供正确的兼容做法如下:

if (!hasOverlayPermission(this)) {
    if (Build.VERSION.SDK_INT >= 23) {
        startActivityForResult(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,Uri.parse("package:" + getPackageName())), Code.CODE_DRAW_OVER_OTHER_APP_PERMISSION);             
        return;
    }
}

private boolean hasOverlayPermission(Context context) {
    return Build.VERSION.SDK_INT < 23 || Settings.canDrawOverlays(context);
}

你可能感兴趣的:(Android,Debug频道)