如何在MIUI中打开“绘图叠加"权限弹出窗口? [英] How to open Draw Overlay permission popup in MIUI?
本文介绍了如何在MIUI中打开“绘图叠加"权限弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 MIUI 中打开此权限弹出窗口.我已经尝试过此代码,但是无法打开特定应用程序的权限管理器弹出窗口.
I want to open this permission popup in MIUI. I have tried this code, but this will not open permission manager popup for a particular app.
public static Intent toPermissionManager(Context context, String packageName) {
Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
String version = getVersionName();
if (MIUI_V5.equals(version)) {
PackageInfo pInfo;
try {
pInfo = context.getPackageManager().getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException ignored) {
return null;
}
intent.setClassName("com.android.settings", "com.miui.securitycenter.permission.AppPermissionsEditor");
intent.putExtra("extra_package_uid", pInfo.applicationInfo.uid);
} else { // MIUI_V6 and above
final String PKG_SECURITY_CENTER = "com.miui.securitycenter";
try {
context.getPackageManager().getPackageInfo(PKG_SECURITY_CENTER, PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException ignored) {
return null;
}
intent.setClassName(PKG_SECURITY_CENTER, "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
intent.putExtra("extra_pkgname", packageName);
}
return intent;
}
推荐答案
调用直接在要使用此permission
的位置onDisplayPopupPermission()
调用此方法.
Call This method directly onDisplayPopupPermission()
where you want to use this permission
.
要检查权限是granted
还是not
,我在上面又添加了一个答案,请检查.
To check permission is granted
or not
I have added one more answer above, please check.
private void onDisplayPopupPermission() {
if (!isMIUI()) {
return;
}
try {
// MIUI 8
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getPackageName());
startActivity(localIntent);
return;
} catch (Exception ignore) {
}
try {
// MIUI 5/6/7
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getPackageName());
startActivity(localIntent);
return;
} catch (Exception ignore) {
}
// Otherwise jump to application details
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
private static boolean isMIUI() {
String device = Build.MANUFACTURER;
if (device.equals("Xiaomi")) {
try {
Properties prop = new Properties();
prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
return prop.getProperty("ro.miui.ui.version.code", null) != null
|| prop.getProperty("ro.miui.ui.version.name", null) != null
|| prop.getProperty("ro.miui.internal.storage", null) != null;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
它将重定向到显示弹出窗口权限屏幕,您可以手动将其更改为开/关
It will redirect to display popup window permission screen you can manually change it to on off
这篇关于如何在MIUI中打开“绘图叠加"权限弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文