android识别不同的rom,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过来空格会消失。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值