生活随笔
收集整理的這篇文章主要介紹了
android 判断手机为小米
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??????? 之前,自己寫了獲取相冊圖片的代碼,在自己手機上測試沒有問題,不過小米手機卻出現問題。在網上搜索資料,發現小米手機與其他德 處理不同。所以今天寫一下判斷手機系統的內容。其實很簡單。
public static final String SYS_EMUI = "sys_emui";public static final String SYS_MIUI = "sys_miui";public static final String SYS_FLYME = "sys_flyme";private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";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";public static String getSystem(){String SYS;try {Properties prop= new Properties();prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));if(prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null|| prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null){SYS = SYS_MIUI;//小米}else if(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){SYS = SYS_EMUI;//華為}else if(getMeizuFlymeOSFlag().toLowerCase().contains("flyme")){SYS = SYS_FLYME;//魅族};} catch (IOException e){e.printStackTrace();return SYS;}return SYS;}public static String getMeizuFlymeOSFlag() {return getSystemProperty("ro.build.display.id", "");}private static String getSystemProperty(String key, String defaultValue) {try {Class<?> clz = Class.forName("android.os.SystemProperties");Method get = clz.getMethod("get", String.class, String.class);return (String)get.invoke(clz, key, defaultValue);} catch (Exception e) {}return defaultValue;}
主要是獲取build.prop文件的內容,然后獲取的信息與那個手機的系統信息想符合,就是哪種手機。判斷的依據是prop.getProperty(),里面的參數每個手機都不一樣,只要一個手機的返回值不為null,那么就可以判斷手機類型。
android 判斷手機為小米就講完了。
就這么簡單。
總結
以上是生活随笔為你收集整理的android 判断手机为小米的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。