How can I detect the device run under Xiomi's MIUI ROM? I'm able to detect Xiomi device with the following code.
String manufacturer = "xiaomi";
if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
}
But how can I detect its MIUI?
How can I detect the device run under Xiomi's MIUI ROM? I'm able to detect Xiomi device with the following code.
String manufacturer = "xiaomi";
if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
}
But how can I detect its MIUI?
Get device properties: adb shell getprop should result with:
And a few more consisting MIUI specific properties
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
String miui = (String) get.invoke(c, "ro.miui.ui.version.code"); // maybe this one or any other 
// if string miui is not empty, bingo
Or, get list of packages: adb shell pm list packages should result with
So you could check with this piece of code:
//installedPackages - list them through package manager
for (String packageName : installedPackages) {
    if (packageName.startsWith("com.miui.")) {
        return true;
    }
}
 
    
    private static boolean isIntentResolved(Context ctx, Intent intent ){
    return (intent!=null && ctx.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null);
}
public static boolean isMIUI(Context ctx) {
return isIntentResolved(ctx, new Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT))
            || isIntentResolved(ctx, new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")))
            || isIntentResolved(ctx, new Intent("miui.intent.action.POWER_HIDE_MODE_APP_LIST").addCategory(Intent.CATEGORY_DEFAULT))
            || isIntentResolved(ctx, new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.powercenter.PowerSettings")));
}
Itents list from taken from https://github.com/dirkam/backgroundable-android
Detect android device info, MIUI version :
public static boolean isMiUi() {
    return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
    }
    public static String getSystemProperty(String propName) {
        String line;
        BufferedReader input = null;
        try {
            java.lang.Process p = Runtime.getRuntime().exec("getprop " + propName);
            input = new BufferedReader(new InputStreamReader(p.getInputStream()),    1024);
            line = input.readLine();
            input.close();
        } catch (IOException ex) {
            return null;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return line;
    }
Credits goes to Muyangmin
