目前我们强大的android系统已经遍及手机,电视,等各个方面。
那么如何判断一个android系统 是支持手机UI 还是 boxUI呢。 如果知道这一属性,那么我们就可以在开发应用程序的时候对这个属性做判断(比如让我们的手机应用不能运行在box上)。怎么做到这一点呢, 今天我就给大家带来方法:
UiModeManager mUiModeManager = (UiModeManager)getSystemService(Context.UI_MODE_SERVICE);
mUiModeManager.getCurrentModeType();
UiModeManager 就是用来获取android 系统配置的UI模式, 通过getCurrentModeType(),就可以拿到模式类型。
android标准版本的模式类型有(各个android 方案公司有可能新加自己的模式,本文忽略):
通过Configuration类就可以获取到这些常量。(Configuration类本文就不做说明了, 有兴趣的可以自行去看,或者给我留言)
/** Constant for {@link #uiMode}: bits that encode the mode type. */
public static final int UI_MODE_TYPE_MASK = 0x0f;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value indicating that no mode type has been set. */
public static final int UI_MODE_TYPE_UNDEFINED = 0x00;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">no
* UI mode</a> resource qualifier specified. */
public static final int UI_MODE_TYPE_NORMAL = 0x01;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">desk</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_DESK = 0x02;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">car</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_CAR = 0x03;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">television</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_TELEVISION = 0x04;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">appliance</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_APPLIANCE = 0x05;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_TYPE_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#UiModeQualifier">watch</a>
* resource qualifier. */
public static final int UI_MODE_TYPE_WATCH = 0x06;
/** Constant for {@link #uiMode}: bits that encode the night mode. */
public static final int UI_MODE_NIGHT_MASK = 0x30;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
* value indicating that no mode type has been set. */
public static final int UI_MODE_NIGHT_UNDEFINED = 0x00;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">notnight</a>
* resource qualifier. */
public static final int UI_MODE_NIGHT_NO = 0x10;
/** Constant for {@link #uiMode}: a {@link #UI_MODE_NIGHT_MASK}
* value that corresponds to the
* <a href="{@docRoot}guide/topics/resources/providing-resources.html#NightQualifier">night</a>
* resource qualifier. */
public static final int UI_MODE_NIGHT_YES = 0x20;