if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
if ("xiaomi".equals(Build.MANUFACTURER.toLowerCase(Locale.ROOT))) {
final Intent intent =new Intent("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName("com.miui.securitycenter",
"com.miui.permcenter.permissions.PermissionsEditorActivity");
intent.putExtra("extra_pkgname", getPackageName());
new AlertDialog.Builder(this)
.setTitle("Please Enable the additional permissions")
.setMessage("You will not receive notifications while the app is in background if you disable these permissions")
.setPositiveButton("Go to Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startActivity(intent);
}
})
.setIcon(android.R.drawable.ic_dialog_info)
.setCancelable(false)
.show();
}else {
Intent overlaySettings = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(overlaySettings, OVERLAY_REQUEST_CODE);
}
}
}