小智 8
这将启动服务短信的意图.一旦用户允许访问服务短信,您就可以阅读通知短信.
if (isMIUI()) {
//this will launch the auto start screen where user can enable the permission for your app
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getActivity().getPackageName());
startActivity(localIntent);
}
public 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;
}
Run Code Online (Sandbox Code Playgroud)
注意:您无法以编程方式获取权限,仅允许来自MIUI的白名单应用.例如,facebook messenger,whatsapp,flipkart等默认情况下都有自动启动选项.