获取系统信息

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);}
}
1
80

1
public class SimpleDeviceUtils {

2
    

3
    public enum SystemType {

4
        /**

5
         * 小米手机(MIUI系统)

6
         */

7
        SYS_MIUI,

8
        /**

9
         * 华为手机(EMUI系统)

10
         */

11
        SYS_EMUI,

12
        /**

13
         * 魅族手机,FLYME系统

14
         */

15
        SYS_FLYME,

16
        /**

17
         * 其他系统

18
         */

19
        SYS_OTHER

20
    }

21
    

22
    private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";

23
    private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";

24
    private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";

25
    

26
    private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level";

27
    private static final String KEY_EMUI_VERSION = "ro.build.version.emui";

28
    private static final String KEY_EMUI_CONFIG_HW_SYS_VERSION = "ro.confg.hw_systemversion";

29
    

30
    /**

31
     * 8.0之后有些系统信息获取不到,没有在各种版本手机上逐一测试

32
     */

33
    public static SystemType getSystemType() {

34
        try {

35
            Properties prop = new Properties();

36
            prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));

37
            if (Build.MANUFACTURER.toLowerCase().equals("xiaomi")//官方提供的判断是否为小米手机(而非MIUI系统)的方法

38
                    || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null//QMUI提供的判断是否是MIUI的方法

39
                    || prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null//下面两个是网上补充的方法,感觉没必要的

40
                    || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null) {

41
                return SystemType.SYS_MIUI;

42
            } else if (isEMUI()//华为

43
                    || prop.getProperty(KEY_EMUI_API_LEVEL, null) != null

44
                    || prop.getProperty(KEY_EMUI_VERSION, null) != null

45
                    || prop.getProperty(KEY_EMUI_CONFIG_HW_SYS_VERSION, null) != null) {

46
                return SystemType.SYS_EMUI;

47
            } else if (isMeizu()//魅族推送SDK中提供的判断是否是魅族的方法

48
                    || DeviceHelper.isMeizu()) {//QMUI提供的判断是否是魅族的方法

49
                return SystemType.SYS_FLYME;

50
            }

51
        } catch (IOException e) {

52
            e.printStackTrace();

53
        }

54
        return SystemType.SYS_OTHER;

55
    }

56
    

57
    @SuppressLint("PrivateApi")

58
    private static boolean isEMUI() {

59
        Class<?>[] clsArray = new Class<?>[]{String.class};

60
        Object[] objArray = new Object[]{"ro.build.version.emui"};

61
        try {

62
            Class<?> SystemPropertiesClass = Class.forName("android.os.SystemProperties");

63
            Method get = SystemPropertiesClass.getDeclaredMethod("get", clsArray);

64
            String version = (String) get.invoke(SystemPropertiesClass, objArray);

65
            Log.i("bqt", "EMUI version is:" + version);

66
            return !TextUtils.isEmpty(version);

67
        } catch (Exception e) {

68
            e.printStackTrace();

69
        }

70
        return false;

71
    }

72
    

73
    /**

74
     * 判断是否为魅族设备

75
     */

76
    private static boolean isMeizu() {

77
        String model = SystemProperties.get("ro.meizu.product.model");

78
        return (!TextUtils.isEmpty(model)) || "meizu".equalsIgnoreCase(Build.BRAND) || "22c4185e".equalsIgnoreCase(Build.BRAND);

79
    }

80
}

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 deniedFileInputStream 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.4boolean 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;}
}
169
1
//判断系统厂商,里面的内容基本都来自QMUI库

2
public class DeviceHelper {

3
    private final static String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";

4
    private static final String KEY_FLYME_VERSION_NAME = "ro.build.display.id";

5
    private final static String FLYME = "flyme";

6
    private final static String MEIZUBOARD[] = {"m9", "M9", "mx", "MX"};

7
    private static String sMiuiVersionName;

8
    private static String sFlymeVersionName;

9
    

10
    static {

11
        Properties properties = new Properties();

12
        

13
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {// android 8.0,读取 /system/build.prop 会报 permission denied

14
            FileInputStream fileInputStream = null;

15
            try {

16
                fileInputStream = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"));

17
                properties.load(fileInputStream);

18
            } catch (Exception e) {

19
                e.printStackTrace();

20
            } finally {

21
                if (fileInputStream != null) {

22
                    try {

23
                        fileInputStream.close();

24
                    } catch (IOException e) {

25
                        e.printStackTrace();

26
                    }

27
                }

28
            }

29
        }

30
        

31
        try {

32
            Class<?> clzSystemProperties = Class.forName("android.os.SystemProperties");

33
            Method getMethod = clzSystemProperties.getDeclaredMethod("get", String.class);

34
            sMiuiVersionName = getLowerCaseName(properties, getMethod, KEY_MIUI_VERSION_NAME);

35
            sFlymeVersionName = getLowerCaseName(properties, getMethod, KEY_FLYME_VERSION_NAME);

36
        } catch (Exception e) {

37
            e.printStackTrace();

38
        }

39
    }

40
    

41
    private static String getLowerCaseName(Properties p, Method get, String key) {

42
        String name = p.getProperty(key);

43
        if (name == null) {

44
            try {

45
                name = (String) get.invoke(null, key);

46
            } catch (Exception e) {

47
                e.printStackTrace();

48
            }

49
        }

50
        if (name != null) name = name.toLowerCase();

51
        return name;

52
    }

53
    

54
    private static boolean sIsTabletChecked = false;

55
    private static boolean sIsTabletValue = false;

56
    

57
    /**

58
     * 判断是否为平板设备

59
     */

60
    public static boolean isTablet(Context context) {

61
        if (sIsTabletChecked) {

62
            return sIsTabletValue;

63
        } else {

64
            sIsTabletChecked = true;

65
            sIsTabletValue = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >=

66
                    Configuration.SCREENLAYOUT_SIZE_LARGE;

67
            return sIsTabletValue;

68
        }

69
    }

70
    

71
    /**

72
     * 判断是否是flyme系统

73
     */

74
    public static boolean isFlyme() {

75
        return !TextUtils.isEmpty(sFlymeVersionName) && sFlymeVersionName.contains(FLYME);

76
    }

77
    

78
    /**

79
     * 判断是否是MIUI系统

80
     */

81
    public static boolean isMIUI() {

82
        return !TextUtils.isEmpty(sMiuiVersionName);

83
    }

84
    

85
    public static boolean isMIUIV5() {

86
        return "v5".equals(sMiuiVersionName);

87
    }

88
    

89
    public static boolean isMIUIV6() {

90
        return "v6".equals(sMiuiVersionName);

91
    }

92
    

93
    public static boolean isMIUIV7() {

94
        return "v7".equals(sMiuiVersionName);

95
    }

96
    

97
    public static boolean isMIUIV8() {

98
        return "v8".equals(sMiuiVersionName);

99
    }

100
    

101
    public static boolean isMIUIV9() {

102
        return "v9".equals(sMiuiVersionName);

103
    }

104
    

105
    public static boolean isFlymeVersionHigher5_2_4() {

106
        //查不到默认高于5.2.4

107
        boolean isHigher = true;

108
        if (sFlymeVersionName != null && !sFlymeVersionName.equals("")) {

109
            Pattern pattern = Pattern.compile("(\\d+\\.){2}\\d");

110
            Matcher matcher = pattern.matcher(sFlymeVersionName);

111
            if (matcher.find()) {

112
                String versionString = matcher.group();

113
                if (versionString != null && !versionString.equals("")) {

114
                    String[] version = versionString.split("\\.");

115
                    if (version.length == 3) {

116
                        if (Integer.valueOf(version[0]) < 5) {

117
                            isHigher = false;

118
                        } else if (Integer.valueOf(version[0]) > 5) {

119
                            isHigher = true;

120
                        } else {

121
                            if (Integer.valueOf(version[1]) < 2) {

122
                                isHigher = false;

123
                            } else if (Integer.valueOf(version[1]) > 2) {

124
                                isHigher = true;

125
                            } else {

126
                                if (Integer.valueOf(version[2]) < 4) {

127
                                    isHigher = false;

128
                                } else if (Integer.valueOf(version[2]) >= 5) {

129
                                    isHigher = true;

130
                                }

131
                            }

132
                        }

133
                    }

134
                    

135
                }

136
            }

137
        }

138
        return isMeizu() && isHigher;

139
    }

140
    

141
    /**

142
     * 判断是否为魅族

143
     */

144
    public static boolean isMeizu() {

145
        return isSpecialBoardPhone(MEIZUBOARD) || isFlyme();

146
    }

147
    

148
    /**

149
     * 判断是否为小米,详见https://dev.mi.com/doc/?p=254

150
     */

151
    public static boolean isXiaomi() {

152
        return Build.MANUFACTURER.toLowerCase().equals("xiaomi");

153
    }

154
    

155
    /**

156
     * 是否是指定型号的手机

157
     */

158
    private static boolean isSpecialBoardPhone(String[] boards) {

159
        String board = android.os.Build.BOARD;

160
        if (board != null) {

161
            for (String b : boards) {

162
                if (board.equals(b)) {

163
                    return true;

164
                }

165
            }

166
        }

167
        return false;

168
    }

169
}

2018-4-20

判断小米 魅族 华为 系统 MIUI EMUI FLYME相关推荐

  1. 安卓 linux it之家,IT之家安卓版 7.07:紧凑排版+适配华为小米魅族OV系统级推送等...

    原标题:IT之家安卓版 7.07:紧凑排版+适配华为小米魅族OV系统级推送等 IT之家 安卓版/iOS版 7.07 今日更新上架发布! 画个重点,大家往下看" 7.x 后续产品规划" ...

  2. android适配华为m5,2019-05-29 Android悬浮窗适配全机型,包含8.0,小米魅族华为悬浮窗权限适配demo看这一篇就够了...

    兼容8.0,小米,魅族,华为等难适配机型都可完美适配. 悬浮窗插入接口 在实现悬浮窗之前,我们需要知道通过什么接口,能够将一个控件放入到屏幕中去. Android的界面绘制,都是通过WindowMan ...

  3. 7代cpu能装虚拟xp系统吗_小米手机最新系统MIUI 11 推荐,附带小米刷机资源

    小米刷机资源 http://www.manosp.com/mandfx/ 第一批MIUI 11系统下载http://www.manosp.com/mandfx/dev/ 适配机型: 小米MIX2S 建 ...

  4. 7代cpu能装虚拟xp系统吗_小米手机最新系统MIUI 11 推荐

    第一批MIUI 11系统下载http://www.manosp.com/mandfx/dev/ 适配机型:     小米MIX2S   建议花三五分钟阅读下方注意事项链接: https://pan.b ...

  5. Android悬浮窗适配全机型,包含8.0,小米魅族华为悬浮窗权限适配demo看这一篇就够了

    机型多杂,适配无法完全兼容,不如换种实现方式,性能比悬浮窗好,不需要权限,效果更好:https://blog.csdn.net/m0_38058826/article/details/10399339 ...

  6. 魅族新系统android o,Flyme下月更新系统内核 魅族9款机型可升安卓7.0

    [IT168 资讯]6月25日是魅族Flyme的5周年纪念日,魅族官方也是兑现了之前的承诺,宣布旗下将有9款机型得到安卓7.0内核升级,最早于7月10日就可升级体验. 基于安卓7.0的Flyme内测招 ...

  7. 集成推送判断设备是小米还是华为

    最近在做推送 集成了华为 小米 得推送 根据判断设备是华为还是小米分别进行处理 现在给出官方给的判断方法 以供参考 public class DeviceUtils {//判断是否是华为系统 官网提供 ...

  8. 判断小米华为等系统 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  9. 华为荣耀5a是android几,系统:MIUI对决EMUI 体验不分伯仲_荣耀 畅玩5A_手机评测-中关村在线...

    相比数年前小米MIUI一枝独秀的情况,目前只能说小米的在系统上的优势已经逐渐丧失了,随着国产手机厂商不断在系统层级上发力,包括荣耀和魅族小米在内的很多品牌的自己系统固件都已经相对成熟,系统功能与体验上 ...

最新文章

  1. 大学计算机思维导图_我学计算机,也会修电脑
  2. logging ,re 模块
  3. hdu5246 超级赛亚ACMer (百度之星初赛)(模拟)
  4. unity3d做会减少的血条_Unity3d中NGUI加强版血条(Healthbar)的制作
  5. JDBC连接MySQL数据库及示例
  6. docker4dotnet #2 容器化主机
  7. 杨国勋:云计算颠覆现有市场和产业格局
  8. matlab gui gif,gui界面可以显示gif动态图,但结束时会报错
  9. SWF文件反编译调试记录
  10. 水下机器人 结构设计
  11. java 文本换行_java写入Excel文本换行
  12. 电子商务运营数据分析
  13. 服务器和客户端信息的获取
  14. 最简单Unity 连招入门--只有20行代码
  15. 关于第七届CNCERT网络安全应急服务支撑单位考核情况的通报
  16. keil配色(黑色背景)
  17. Mysql数据库报错:Row size too large (> 8126). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DY
  18. 全面掌控!打造智慧城市建设的“领导驾驶舱”
  19. proc_create的使用方法
  20. SimpleMind for Mac v1.31.0 中文版 小巧的思维导图工具

热门文章

  1. glibc==2.17 报错
  2. springboot出现“org.hibernate.proxy.HibernateProxy. Forgot to register a type adapter?“的解决办法
  3. 比尔盖茨、贝佐斯、扎克伯格-硅谷大佬的书单
  4. Pyramid Mask Text Detector阅读笔记
  5. suse linux最新版本,SUSE Linux Enterprise Server 15正式版发布下载
  6. FE节点挂掉且重启报错sleepycat.je.LockTimeoutException: (JE 7.3.7) Lock expired
  7. 网络对抗技术---实验一
  8. 装机不求人,10 分钟电脑配置挑选速成攻略
  9. VFIO Introduction
  10. OCR -上传图片 自动识别文字并填充