如何在android中以编程方式检测MIUI ROM?

时间:2017-12-02 17:16:49

标签: android miui

如何在Xiomi的MIUI ROM下检测设备运行?我能用以下代码检测Xiomi设备。

String manufacturer = "xiaomi";
if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
}

但我怎样才能发现它的MIUI?

2 个答案:

答案 0 :(得分:1)

  1. 获取设备属性: adb shell getprop 结果应该是:

    • [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]
  2. 还有一些包含MIUI特定属性

    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. 或者,获取包列表: adb shell pm list packages 应该以

      结果
      • 包:com.miui.system
      • 包:com.android.calendar
      • 包:com.miui.translation.kingsoft
      • 包:com.miui.virtualsim
      • 包:com.miui.compass ...
    2. 所以你可以查看这段代码:

      //installedPackages - list them through package manager
      for (String packageName : installedPackages) {
          if (packageName.startsWith("com.miui.")) {
              return true;
          }
      }
      

答案 1 :(得分:0)

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) {
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")))}

内容清单来自https://github.com/dirkam/backgroundable-android