5

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?

Cœur
  • 34,719
  • 24
  • 185
  • 251
tan
  • 1,554
  • 2
  • 12
  • 34

2 Answers2

7
  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;
    }
}
Drez
  • 458
  • 3
  • 10
6
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

A.J.
  • 1,452
  • 17
  • 21
Meltzer
  • 117
  • 2
  • 9