android多機型識別

走安卓開發不可避免的遇到很多機型,并且去適配。下面分享兩個工具類,可以直接識別機型:

**

* Created with IntelliJ IDEA.

* **********************************

* User: skura_l

* Date: 2016年 01月 20日

*@QQ: 1234567890

* **********************************

*/

public classAndtoidRomUtil {

? ? ? ? ? ? ? ? private static finalStringKEY_EMUI_VERSION_CODE="ro.build.version.emui";

? ? ? ? ? ? ? ? private static finalStringKEY_MIUI_VERSION_CODE="ro.miui.ui.version.code";

? ? ? ? ? ? ? ? private static finalStringKEY_MIUI_VERSION_NAME="ro.miui.ui.version.name";

? ? ? ? ? ? ? ? private static finalStringKEY_MIUI_INTERNAL_STORAGE="ro.miui.internal.storage";

/**

* 華為rom

*

*@return

*/

public static booleanisEMUI() {

? try{

? ? ? finalBuildProperties prop = BuildProperties.newInstance();

? ? ? ?returnprop.getProperty(KEY_EMUI_VERSION_CODE, null) !=null;

}catch(finalIOException e) {

? ? ? ?return false;

? }

}

/**

* 小米rom

*

*@return

*/

public static booleanisMIUI() {

try{

? ? ? ? ? ?final String type = android.os.Build.MODEL;

? ? ? ? ? ?final Build Properties prop = Build Properties.newInstance();

? ? ? ? ? /*String rom = "" + prop.getProperty(KEY_MIUI_VERSION_CODE, null) + ? ? ? ? ? ? ? ? ? ? ?prop.getProperty(KEY_MIUI_VERSION_NAME, null)+prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null);

? ? ? ? ? ?Log.d("Android_Rom", rom);*/

? ? ? ? ? ?returnprop.getProperty(KEY_MIUI_VERSION_CODE, null) !=null

? ? ? ? ? ?|| prop.getProperty(KEY_MIUI_VERSION_NAME, null) !=null

? ? ? ? ? ? || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) !=null

? ? ? ? ? ?|| type.length() >"MI".length() && type.substring(0,"MI".length()).equals("MI");

? ? ? ? }catch(finalIOException e) {

return false;

}

}

/**

* 魅族rom

*

*@return

*/

public static booleanisFlyme() {

try{

? ? ? ? ?finalMethod method = Build.class.getMethod("hasSmartBar");

? ? ? ? ? ?returnmethod !=null;

}catch(finalException e) {

? ? ? ? ? return false;

? }

?}

}


/////////////////

public classBuildProperties {

? ? ? ? ? ?private finalPropertiesproperties;

? ? ? ? ? ?privateBuildProperties()throwsIOException {

? ? ? ? ? ?properties=newProperties();

? ? ? ? ? ? ?properties.load(newFileInputStream(newFile(Environment.getRootDirectory(),"build.prop")));

}

public booleancontainsKey(finalObject key) {

? ? ? ? ? ? ?returnproperties.containsKey(key);

}

public booleancontainsValue(finalObject value) {

? ? ? ? ? ? ? returnproperties.containsValue(value);

}

publicSet>entrySet() {

? ?returnproperties.entrySet();

}

publicStringgetProperty(finalString name) {

? ? ? ?returnproperties.getProperty(name);

}

publicStringgetProperty(finalString name, finalString defaultValue) {

? ? ? ?returnproperties.getProperty(name,defaultValue);

}

public booleanisEmpty() {

? ? ? ?returnproperties.isEmpty();

}

publicEnumerationkeys() {

? ?returnproperties.keys();

}

publicSetkeySet() {

returnproperties.keySet();

}

public intsize() {

returnproperties.size();

}

publicCollectionvalues() {

returnproperties.values();

}

public staticBuildPropertiesnewInstance()throwsIOException {

return newBuildProperties();

}

}


注意: 其實只要這樣就可以了String type = android.os.Build.MODEL; 這個返回的東西就可以區別手機,打印出來看就行了。 簡書沒用過多久,完全不會排版,而且直接copy過來空格會消失。。。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,869評論 18 139
  • 最近有個需求需要建一個service永遠在后臺運行來接收推送消息和一些定時器工作,首先想到的就是雙進程守護原則...
    lib93閱讀 1,231評論 0 2
  • 其實呢,我屬于小白一枚,剛剛入手學習微信平臺運營。以下呢,是我的作業,初次接觸,請大家多多指教哦! 首先,我注冊了...
    摩羯段閱讀 178評論 0 0
  • 因為我們的應用是單頁客戶端應用,當使用 history 模式時,URL 就像正常的 url,可以直接訪問,但是因為...
    qhaobaba閱讀 2,831評論 1 1
  • 昨天終于看過了《二十二》,其中印象最深刻的是山西省志愿者,最后他說一開始了解這些老人,是為了讓日本給她們應有的賠償...
    一個人的太陽_閱讀 221評論 0 0