How to get Permission for read "Service SMS" in MIUI 8+ (programmatically).
This will launch the intent for service sms. Once user will allow the access for service sms you will able to read the notification sms.
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;
}
Note: you can not take the permission programmatically it's only allowed for whitelisted app from MIUI. for example- facebook messenger, whatsapp, flipkart etc have autostart option by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With