如何在 MIUI 中打开 Draw Overlay 权限弹出窗口? [英] How to open Draw Overlay permission popup in MIUI?
本文介绍了如何在 MIUI 中打开 Draw Overlay 权限弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 MIUI 中打开此权限弹出窗口.我已经尝试过此代码,但这不会打开特定应用程序的权限管理器弹出窗口.
public static Intent toPermissionManager(Context context, String packageName) {Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");字符串版本 = getVersionName();如果(MIUI_V5.equals(版本)){PackageInfo pInfo;尝试 {pInfo = context.getPackageManager().getPackageInfo(packageName, 0);} catch (PackageManager.NameNotFoundException 被忽略) {返回空;}intent.setClassName("com.android.settings", "com.miui.securitycenter.permission.AppPermissionsEditor");intent.putExtra("extra_package_uid", pInfo.applicationInfo.uid);} else {//MIUI_V6 及以上final String PKG_SECURITY_CENTER = "com.miui.securitycenter";尝试 {context.getPackageManager().getPackageInfo(PKG_SECURITY_CENTER, PackageManager.GET_ACTIVITIES);} catch (PackageManager.NameNotFoundException 被忽略) {返回空;}intent.setClassName(PKG_SECURITY_CENTER, "com.miui.permcenter.permissions.AppPermissionsEditorActivity");intent.putExtra("extra_pkgname", packageName);}回归意图;}
解决方案
在你想使用这个权限
的地方直接onDisplayPopupPermission()
调用这个方法.
要检查权限是granted
还是not
我在上面又添加了一个答案,请检查.
private void onDisplayPopupPermission() {如果 (!isMIUI()) {返回;}尝试 {//MIUI 8Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");localIntent.putExtra("extra_pkgname", getPackageName());开始活动(本地意图);返回;} catch(忽略异常){}尝试 {//MIUI 5/6/7Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");localIntent.putExtra("extra_pkgname", getPackageName());开始活动(本地意图);返回;} catch(忽略异常){}//否则跳转到应用程序详细信息意图意图 = 新意图(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);Uri uri = Uri.fromParts("package", getPackageName(), null);意图.setData(uri);开始活动(意图);}私有静态布尔值 isMIUI() {字符串设备 = Build.MANUFACTURER;如果(设备.等于(小米")){尝试 {属性 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();}}返回假;}
<块引用>
它将重定向到显示弹出窗口权限屏幕,您可以手动将其更改为开/关
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;
}
解决方案
Call This method directly onDisplayPopupPermission()
where you want to use this permission
.
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 中打开 Draw Overlay 权限弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文