判断是为魅族系统(Flyme OS)

方法一:
原理:魅族系统(Flyme)5.1可以通过是否有hasSmartBar进行判断。
/**
* 判断是否为魅族系统 (注意:此方法对于最新的Flyme(基于Android 5.1)无效.)
* <h3>Version</h3> 1.0
* <h3>CreateTime</h3> 2016/6/8,17:06
* <h3>UpdateTime</h3> 2016/6/8,17:06
* <h3>CreateAuthor</h3>
* <h3>UpdateAuthor</h3>
* <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.)
*
* @return true 为魅族系统 否则不是
*/
public static boolean isFlyme() {
try {
final Method method = Build.class.getMethod("hasSmartBar");
return method != null;
} catch (final Exception e) {
return false;
}
}
/**
* 获取魅族系统SmartBar的高度,
* <h3>Version</h3> 1.0
* <h3>CreateTime</h3> 2016/6/8,17:07
* <h3>UpdateTime</h3> 2016/6/8,17:07
* <h3>CreateAuthor</h3>
* <h3>UpdateAuthor</h3>
* <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.)
*
* @param context
* @param actionbar
* @return
*/
public static int getSmartBarHeight(Context context, ActionBar actionbar) {
if (actionbar != null)
try {
Class c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
Field field = c.getField("mz_action_button_min_height");
int height = Integer.parseInt(field.get(obj).toString());
return context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();

actionbar.getHeight();
}
return 0;
}
注意:此方法只适合Fyme 5.1之前的版本。
方法二:也可以判断Fyme 5.1
/**
* 判断是魅族操作系统
* <h3>Version</h3> 1.0
* <h3>CreateTime</h3> 2016/6/18,9:43
* <h3>UpdateTime</h3> 2016/6/18,9:43
* <h3>CreateAuthor</h3> vera
* <h3>UpdateAuthor</h3>
* <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.)
* @return true 为魅族系统 否则不是
*/
public static boolean isMeizuFlymeOS() {
/* 获取魅族系统操作版本标识*/
String meizuFlymeOSFlag = getSystemProperty("ro.build.display.id","");
if (TextUtils.isEmpty(meizuFlymeOSFlag)){
return false;
}else if (meizuFlymeOSFlag.contains("flyme") || meizuFlymeOSFlag.toLowerCase().contains("flyme")){
return true;
}else {
return false;
}
}


/**
* 获取系统属性
* <h3>Version</h3> 1.0
* <h3>CreateTime</h3> 2016/6/18,9:35
* <h3>UpdateTime</h3> 2016/6/18,9:35
* <h3>CreateAuthor</h3> vera
* <h3>UpdateAuthor</h3>
* <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.)
* @param key ro.build.display.id
* @param defaultValue 默认值
* @return 系统操作版本标识
*/
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 (ClassNotFoundException e) {
LogUtil.logErrorMessage("SystemUtil=================>"+e.getMessage());
return null;
} catch (NoSuchMethodException e) {
LogUtil.logErrorMessage("SystemUtil=================>"+e.getMessage());
return null;
} catch (IllegalAccessException e) {
LogUtil.logErrorMessage("SystemUtil=================>"+e.getMessage());
return null;
} catch (IllegalArgumentException e) {
LogUtil.logErrorMessage("SystemUtil=================>"+e.getMessage());
return null;
} catch (InvocationTargetException e) {
LogUtil.logErrorMessage("SystemUtil=================>"+e.getMessage());
return null;
}
}
其他Flyme属性设置参考魅族官网 Flyme API
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值