如何在Xiomi的MIUI ROM下检测设备运行?我能用以下代码检测Xiomi设备。
String manufacturer = "xiaomi";
if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
}
但我怎样才能发现它的MIUI?
答案 0 :(得分:1)
获取设备属性: adb shell getprop 结果应该是:
还有一些包含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
或者,获取包列表: adb shell pm list packages 应该以
结果所以你可以查看这段代码:
//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")))}