android-M关于SYSTEM_ALERT_WINDOW权限申请

安卓M以下按照普通权限申请即可

安卓M以上需要需要调用以下方法:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M&&!Settings.canDrawOverlays(this)) {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
    intent.setData(Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, 100);
}

之后在onActivityResult接收返回结果:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode==100){
        if (Settings.canDrawOverlays(this)) {
            //TODO DO SOMETHING
        }
    }
}

 

你可能感兴趣的:(Android)