Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect MIUI ROM programmatically in android?

Tags:

android

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?

like image 633
tan Avatar asked Dec 24 '22 12:12

tan


1 Answers

  1. Get device properties: adb shell getprop should result with:

    • [ro.miui.cust_variant]: [x]
    • [ro.miui.has_cust_partition]: [x]
    • [ro.miui.has_handy_mode_sf]: [x]
    • [ro.miui.has_real_blur]: [x]
    • [ro.miui.mcc]: [xxx]
    • [ro.miui.mnc]: [xxx]
    • [ro.miui.region]: [x]
    • [ro.miui.ui.version.code]: [x]
    • [ro.miui.ui.version.name]: [x]
    • [ro.miui.version.code_time]: [xxx]

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
  1. Or, get list of packages: adb shell pm list packages should result with

    • package:com.miui.system
    • package:com.android.calendar
    • package:com.miui.translation.kingsoft
    • package:com.miui.virtualsim
    • package:com.miui.compass ...

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;
    }
}
like image 170
Drez Avatar answered Dec 27 '22 03:12

Drez