官方介绍
Allows an app to create windows using the type TYPE_SYSTEM_ALERT
, shown on top of all other apps. Very few apps should use this permission; these windows are intended for system-level interaction with the user.
Note: If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action ACTION_MANAGE_OVERLAY_PERMISSION
. The app can check whether it has this authorization by calling Settings.canDrawOverlays()
.
Protection level: signature
Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"
解决代码
//权限判断
if (Build.VERSION.SDK_INT >= 23) {
if(!Settings.canDrawOverlays(getApplicationContext())) {
//启动Activity让用户授权
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivity(intent);
return;
} else {
//执行6.0以上绘制代码
}
} else {
//执行6.0以下绘制代码
}