How to detect MIUI ROM programmatically in android?
Asked Answered
O

3

7

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?

Ornithopter answered 2/12, 2017 at 17:16 Comment(2)
Try Build.DISPLAYTardigrade
Means from android studio you need to run application but device not display? are you talkign about this?Melisma
I
8
  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;
    }
}
Immunize answered 14/2, 2018 at 22:4 Comment(0)
C
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

Cubiculum answered 30/12, 2018 at 10:56 Comment(0)
B
0

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

Bekah answered 14/11, 2022 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.