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