判断小米 魅族 华为 系统 MIUI EMUI FLYME
Markdown版本笔记 | 我的GitHub首页 | 我的博客 | 我的微信 | 我的邮箱 |
---|---|---|---|---|
MyAndroidBlogs | baiqiantao | baiqiantao | bqt20094 | baiqiantao@sina.com |
目录
判断小米华为系统
工具类:获取系统信息
public class SimpleDeviceUtils {
public enum SystemType {
/**
* 小米手机(MIUI系统)
*/
SYS_MIUI,
/**
* 华为手机(EMUI系统)
*/
SYS_EMUI,
/**
* 魅族手机,FLYME系统
*/
SYS_FLYME,
/**
* 其他系统
*/
SYS_OTHER
}
private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";
private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level";
private static final String KEY_EMUI_VERSION = "ro.build.version.emui";
private static final String KEY_EMUI_CONFIG_HW_SYS_VERSION = "ro.confg.hw_systemversion";
/**
* 8.0之后有些系统信息获取不到,没有在各种版本手机上逐一测试
*/
public static SystemType getSystemType() {
try {
Properties prop = new Properties();
prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
if (Build.MANUFACTURER.toLowerCase().equals("xiaomi")//官方提供的判断是否为小米手机(而非MIUI系统)的方法
|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null//QMUI提供的判断是否是MIUI的方法
|| prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null//下面两个是网上补充的方法,感觉没必要的
|| prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null) {
return SystemType.SYS_MIUI;
} else if (isEMUI()//华为
|| prop.getProperty(KEY_EMUI_API_LEVEL, null) != null
|| prop.getProperty(KEY_EMUI_VERSION, null) != null
|| prop.getProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, null) != null) {
return SystemType.SYS_EMUI;
} else if (isMeizu()//魅族推送SDK中提供的判断是否是魅族的方法
|| DeviceHelper.isMeizu()) {//QMUI提供的判断是否是魅族的方法
return SystemType.SYS_FLYME;
}
} catch (IOException e) {
e.printStackTrace();
}
return SystemType.SYS_OTHER;
}
@SuppressLint("PrivateApi")
private static boolean isEMUI() {
Class<?>[] clsArray = new Class<?>[]{String.class};
Object[] objArray = new Object[]{"ro.build.version.emui"};
try {
Class<?> SystemPropertiesClass = Class.forName("android.os.SystemProperties");
Method get = SystemPropertiesClass.getDeclaredMethod("get", clsArray);
String version = (String) get.invoke(SystemPropertiesClass, objArray);
Log.i("bqt", "EMUI version is:" + version);
return !TextUtils.isEmpty(version);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 判断是否为魅族设备
*/
private static boolean isMeizu() {
String model = SystemProperties.get("ro.meizu.product.model");
return (!TextUtils.isEmpty(model)) || "meizu".equalsIgnoreCase(Build.BRAND) || "22c4185e".equalsIgnoreCase(Build.BRAND);
}
}
QMUI库中提供的方法
//判断系统厂商,里面的内容基本都来自QMUI库
public class DeviceHelper {
private final static String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
private static final String KEY_FLYME_VERSION_NAME = "ro.build.display.id";
private final static String FLYME = "flyme";
private final static String MEIZUBOARD[] = {"m9", "M9", "mx", "MX"};
private static String sMiuiVersionName;
private static String sFlymeVersionName;
static {
Properties properties = new Properties();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {// android 8.0,读取 /system/build.prop 会报 permission denied
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"));
properties.load(fileInputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
try {
Class<?> clzSystemProperties = Class.forName("android.os.SystemProperties");
Method getMethod = clzSystemProperties.getDeclaredMethod("get", String.class);
sMiuiVersionName = getLowerCaseName(properties, getMethod, KEY_MIUI_VERSION_NAME);
sFlymeVersionName = getLowerCaseName(properties, getMethod, KEY_FLYME_VERSION_NAME);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getLowerCaseName(Properties p, Method get, String key) {
String name = p.getProperty(key);
if (name == null) {
try {
name = (String) get.invoke(null, key);
} catch (Exception e) {
e.printStackTrace();
}
}
if (name != null) name = name.toLowerCase();
return name;
}
private static boolean sIsTabletChecked = false;
private static boolean sIsTabletValue = false;
/**
* 判断是否为平板设备
*/
public static boolean isTablet(Context context) {
if (sIsTabletChecked) {
return sIsTabletValue;
} else {
sIsTabletChecked = true;
sIsTabletValue = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >=
Configuration.SCREENLAYOUT_SIZE_LARGE;
return sIsTabletValue;
}
}
/**
* 判断是否是flyme系统
*/
public static boolean isFlyme() {
return !TextUtils.isEmpty(sFlymeVersionName) && sFlymeVersionName.contains(FLYME);
}
/**
* 判断是否是MIUI系统
*/
public static boolean isMIUI() {
return !TextUtils.isEmpty(sMiuiVersionName);
}
public static boolean isMIUIV5() {
return "v5".equals(sMiuiVersionName);
}
public static boolean isMIUIV6() {
return "v6".equals(sMiuiVersionName);
}
public static boolean isMIUIV7() {
return "v7".equals(sMiuiVersionName);
}
public static boolean isMIUIV8() {
return "v8".equals(sMiuiVersionName);
}
public static boolean isMIUIV9() {
return "v9".equals(sMiuiVersionName);
}
public static boolean isFlymeVersionHigher5_2_4() {
//查不到默认高于5.2.4
boolean isHigher = true;
if (sFlymeVersionName != null && !sFlymeVersionName.equals("")) {
Pattern pattern = Pattern.compile("(\\d+\\.){2}\\d");
Matcher matcher = pattern.matcher(sFlymeVersionName);
if (matcher.find()) {
String versionString = matcher.group();
if (versionString != null && !versionString.equals("")) {
String[] version = versionString.split("\\.");
if (version.length == 3) {
if (Integer.valueOf(version[0]) < 5) {
isHigher = false;
} else if (Integer.valueOf(version[0]) > 5) {
isHigher = true;
} else {
if (Integer.valueOf(version[1]) < 2) {
isHigher = false;
} else if (Integer.valueOf(version[1]) > 2) {
isHigher = true;
} else {
if (Integer.valueOf(version[2]) < 4) {
isHigher = false;
} else if (Integer.valueOf(version[2]) >= 5) {
isHigher = true;
}
}
}
}
}
}
}
return isMeizu() && isHigher;
}
/**
* 判断是否为魅族
*/
public static boolean isMeizu() {
return isSpecialBoardPhone(MEIZUBOARD) || isFlyme();
}
/**
* 判断是否为小米,详见https://dev.mi.com/doc/?p=254
*/
public static boolean isXiaomi() {
return Build.MANUFACTURER.toLowerCase().equals("xiaomi");
}
/**
* 是否是指定型号的手机
*/
private static boolean isSpecialBoardPhone(String[] boards) {
String board = android.os.Build.BOARD;
if (board != null) {
for (String b : boards) {
if (board.equals(b)) {
return true;
}
}
}
return false;
}
}
public class SimpleDeviceUtils {
public enum SystemType {
/**
* 小米手机(MIUI系统)
*/
SYS_MIUI,
/**
* 华为手机(EMUI系统)
*/
SYS_EMUI,
/**
* 魅族手机,FLYME系统
*/
SYS_FLYME,
/**
* 其他系统
*/
SYS_OTHER
}
private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";
private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level";
private static final String KEY_EMUI_VERSION = "ro.build.version.emui";
private static final String KEY_EMUI_CONFIG_HW_SYS_VERSION = "ro.confg.hw_systemversion";
/**
* 8.0之后有些系统信息获取不到,没有在各种版本手机上逐一测试
*/
public static SystemType getSystemType() {
try {
Properties prop = new Properties();
prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
if (Build.MANUFACTURER.toLowerCase().equals("xiaomi")//官方提供的判断是否为小米手机(而非MIUI系统)的方法
|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null//QMUI提供的判断是否是MIUI的方法
|| prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null//下面两个是网上补充的方法,感觉没必要的
|| prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null) {
return SystemType.SYS_MIUI;
} else if (isEMUI()//华为
|| prop.getProperty(KEY_EMUI_API_LEVEL, null) != null
|| prop.getProperty(KEY_EMUI_VERSION, null) != null
|| prop.getProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, null) != null) {
return SystemType.SYS_EMUI;
} else if (isMeizu()//魅族推送SDK中提供的判断是否是魅族的方法
|| DeviceHelper.isMeizu()) {//QMUI提供的判断是否是魅族的方法
return SystemType.SYS_FLYME;
}
} catch (IOException e) {
e.printStackTrace();
}
return SystemType.SYS_OTHER;
}
@SuppressLint("PrivateApi")
private static boolean isEMUI() {
Class<?>[] clsArray = new Class<?>[]{String.class};
Object[] objArray = new Object[]{"ro.build.version.emui"};
try {
Class<?> SystemPropertiesClass = Class.forName("android.os.SystemProperties");
Method get = SystemPropertiesClass.getDeclaredMethod("get", clsArray);
String version = (String) get.invoke(SystemPropertiesClass, objArray);
Log.i("bqt", "EMUI version is:" + version);
return !TextUtils.isEmpty(version);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 判断是否为魅族设备
*/
private static boolean isMeizu() {
String model = SystemProperties.get("ro.meizu.product.model");
return (!TextUtils.isEmpty(model)) || "meizu".equalsIgnoreCase(Build.BRAND) || "22c4185e".equalsIgnoreCase(Build.BRAND);
}
}
//判断系统厂商,里面的内容基本都来自QMUI库
public class DeviceHelper {
private final static String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
private static final String KEY_FLYME_VERSION_NAME = "ro.build.display.id";
private final static String FLYME = "flyme";
private final static String MEIZUBOARD[] = {"m9", "M9", "mx", "MX"};
private static String sMiuiVersionName;
private static String sFlymeVersionName;
static {
Properties properties = new Properties();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {// android 8.0,读取 /system/build.prop 会报 permission denied
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"));
properties.load(fileInputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
try {
Class<?> clzSystemProperties = Class.forName("android.os.SystemProperties");
Method getMethod = clzSystemProperties.getDeclaredMethod("get", String.class);
sMiuiVersionName = getLowerCaseName(properties, getMethod, KEY_MIUI_VERSION_NAME);
sFlymeVersionName = getLowerCaseName(properties, getMethod, KEY_FLYME_VERSION_NAME);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getLowerCaseName(Properties p, Method get, String key) {
String name = p.getProperty(key);
if (name == null) {
try {
name = (String) get.invoke(null, key);
} catch (Exception e) {
e.printStackTrace();
}
}
if (name != null) name = name.toLowerCase();
return name;
}
private static boolean sIsTabletChecked = false;
private static boolean sIsTabletValue = false;
/**
* 判断是否为平板设备
*/
public static boolean isTablet(Context context) {
if (sIsTabletChecked) {
return sIsTabletValue;
} else {
sIsTabletChecked = true;
sIsTabletValue = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >=
Configuration.SCREENLAYOUT_SIZE_LARGE;
return sIsTabletValue;
}
}
/**
* 判断是否是flyme系统
*/
public static boolean isFlyme() {
return !TextUtils.isEmpty(sFlymeVersionName) && sFlymeVersionName.contains(FLYME);
}
/**
* 判断是否是MIUI系统
*/
public static boolean isMIUI() {
return !TextUtils.isEmpty(sMiuiVersionName);
}
public static boolean isMIUIV5() {
return "v5".equals(sMiuiVersionName);
}
public static boolean isMIUIV6() {
return "v6".equals(sMiuiVersionName);
}
public static boolean isMIUIV7() {
return "v7".equals(sMiuiVersionName);
}
public static boolean isMIUIV8() {
return "v8".equals(sMiuiVersionName);
}
public static boolean isMIUIV9() {
return "v9".equals(sMiuiVersionName);
}
public static boolean isFlymeVersionHigher5_2_4() {
//查不到默认高于5.2.4
boolean isHigher = true;
if (sFlymeVersionName != null && !sFlymeVersionName.equals("")) {
Pattern pattern = Pattern.compile("(\\d+\\.){2}\\d");
Matcher matcher = pattern.matcher(sFlymeVersionName);
if (matcher.find()) {
String versionString = matcher.group();
if (versionString != null && !versionString.equals("")) {
String[] version = versionString.split("\\.");
if (version.length == 3) {
if (Integer.valueOf(version[0]) < 5) {
isHigher = false;
} else if (Integer.valueOf(version[0]) > 5) {
isHigher = true;
} else {
if (Integer.valueOf(version[1]) < 2) {
isHigher = false;
} else if (Integer.valueOf(version[1]) > 2) {
isHigher = true;
} else {
if (Integer.valueOf(version[2]) < 4) {
isHigher = false;
} else if (Integer.valueOf(version[2]) >= 5) {
isHigher = true;
}
}
}
}
}
}
}
return isMeizu() && isHigher;
}
/**
* 判断是否为魅族
*/
public static boolean isMeizu() {
return isSpecialBoardPhone(MEIZUBOARD) || isFlyme();
}
/**
* 判断是否为小米,详见https://dev.mi.com/doc/?p=254
*/
public static boolean isXiaomi() {
return Build.MANUFACTURER.toLowerCase().equals("xiaomi");
}
/**
* 是否是指定型号的手机
*/
private static boolean isSpecialBoardPhone(String[] boards) {
String board = android.os.Build.BOARD;
if (board != null) {
for (String b : boards) {
if (board.equals(b)) {
return true;
}
}
}
return false;
}
}
2018-4-20
判断小米 魅族 华为 系统 MIUI EMUI FLYME的更多相关文章
- 「知乎」对中国用户而言,Pure Android 是否比 MIUI 或 Flyme 体验更好? - Donnie的博客
这篇文章转载自我在知乎上的回答 哎呀-不要站队嘛.其实这是一个很有意思的题目,让我们一点点来看 哦对,谢妖-.本人是Nexus 5用户,系统当然是Pure Android KitKat啦(臭谷粉!点D ...
- 小米平板2 win10 MIUI互刷教程
在这篇文章中,我们会为大家提供Windows 10版小米平板2刷入MIUI和MIUI版小米平板2刷入Windows 10的两组教程. 不过从Win 10刷MIUI需要用原生安卓系统过渡来统一bios版 ...
- 针对在webview模式中,小米魅族手机不支持html5原生video的control的解决办法![原创]
其实,解决办法就是,重新写个control控制功能,.同样用流行的video.js可以实现 第一步就是增加个播放的图片..要不然没有按钮多难看! <div class="videoDi ...
- swift学习笔记 - 判断当前运行的系统和平台
最近代码需要判断代码运行的系统与平台,下面总结了一下swift下一些可以用来判断的属性: // 代码运行在32位的 Windows public var TARGET_OS_MAC: Int32 { ...
- javascript如何判断手机是什么系统
做H5页面的时候,经常会用到判断手机是什么系统,根据系统的型号,实现不同的效果,那么如何判断显示页面的手机型号呢? (function(){ var isMobile={ Android:functi ...
- 如何判断你的windows系统是32位还是64位?
[学习笔记] 如 何判断你的windows系统是32位还是64位? java -version时,如果没有64就是32位的.eclipse.ini中如果没有64,就是32位的.但是我们的ini文件里面 ...
- 小米开源监控系统Open-Falcon安装使用笔记
小米开源监控系统Open-Falcon安装使用笔记-BB保你大-51CTO博客 https://blog.51cto.com/chenguomin/1865550
- android通过代码获取华为手机的EMUI系统版本号
因为app中用到华为推送,但是华为推送在不同版本上是存在不同问题的,需要单独来处理. 那么最基本的问题是要获取EMUI系统的版本号. 上网翻了很多博客帖子,基本上是在获取root权限下去读取/syst ...
- 获取Win和Linux系统启动时间,类似uptime功能,用于判断是否修改过系统时间
目录 前言 测试代码 Win测试 Linux测试 总结 前言 有时候需要判断系统是否有修改过时间,最简单的方法就是获取当前时间A,然后sleep X秒,然后获取 时间B,如果 时间B - 时间A ≠ ...
随机推荐
- PHP 命名空间与自动加载机制介绍
include 和 require 是PHP中引入文件的两个基本方法.在小规模开发中直接使用 include 和 require 没哟什么不妥,但在大型项目中会造成大量的 include 和 requ ...
- 【原】Spring整合Redis(第一篇)—SDR简述
1.SDR说明 Spring Data Redis(SDR),是SpringFramework提供的一套简化访问Redis的API,是对Jedis的又一层封装. SDR集成了Jedis,JRedis, ...
- 一、java概述
一.概述 java不仅仅是一门编程语言,还是一个由一系列计算机软件和规范形成的技术体系. 提供了完整的开发和跨平台部署的支持环境.用途广泛. 结构严谨.面向对象.摆脱硬件平台的束缚. ...
- Spring @Value的$和#用法区别
@Value的值有两类: ① ${ property : default_value } ② #{ obj.property? : default_value } 就是说,第一个注入的是外部参数对应的 ...
- Calculate CAN bit timing parameters
Calculate CAN bit timing parameters TSYNC_SEG === 1 TSEG1 = Prop_Seg + Phase_Seg1 TSEG2 = Phase_Seg2 ...
- OpenSSL开发学习总结
from https://mp.weixin.qq.com/s/sJBGJ88_-N-LdA8EHywfAA 1.对称加密算法 对称加密算法只使用一个密钥.数据的发送方准备好原始数据和一个加密密钥,加 ...
- After 2 years, I have finally solved my "Slow Hyper-V Guest Network Performance" issue. I am ecstatic.
Edit - It should be known that I was initially researching this issue back in 2012 and the solution ...
- .Net Discovery系列之十-深入理解平台机制与性能影响(上)
转眼间<.Net Discovery>系列文章已经推出1年了,本文为该系列的第10-13篇文章,在本文中将对以前所讲的.Net平台知识做一个小小的总结与机制分析,引出并重点介绍这些机制对程 ...
- C#交换两个变量值的多种写法
在学习.Net/C#或者任何一门面向对象语言的初期,大家都写过交换两个变量值,通常是通过临时变量来实现.本篇使用多种方式实现两个变量值的交换. 假设int x =1; int y = 2;现在交换两个 ...
- Odoo(OpenERP)配置文件openerp-server.conf详解
原文地址:http://blog.csdn.net/wangnan537/article/details/42283465 [options] ; addons模块的查找路径 addons_path ...