【问题标题】:How to detect MIUI ROM programmatically in android?如何在android中以编程方式检测MIUI ROM?
【发布时间】:2018-05-16 13:35:33
【问题描述】:

如何检测运行在小米MIUI ROM下的设备?我可以使用以下代码检测到小米设备。

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

但是如何检测它的 MIUI?

【问题讨论】:

  • 试试Build.DISPLAY
  • 意味着来自android studio的你需要运行应用程序但设备不显示?你在谈论这个吗?

标签: android miui


【解决方案1】:
  1. 获取设备属性: adb shell 获取属性 结果应该是:

    • [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]

还有一些 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 结果应该是

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

所以你可以检查这段代码:

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

【讨论】:

    【解决方案2】:
    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

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2019-03-24
      相关资源
      最近更新 更多