如何知道android的设备类型

时间:2015-11-30 17:42:01

标签: android screen-size television

我怎么知道平板电脑,手机和电视盒安卓之间的设备类型? 我已经尝试使用javascript调整屏幕大小,但有些平板电脑的屏幕大小与电视相同。

1 个答案:

答案 0 :(得分:0)

检查是平板电脑设备。

private static boolean isTabletDevice(Context activityContext) {
boolean device_large = ((activityContext.getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK) ==
        Configuration.SCREENLAYOUT_SIZE_LARGE);

if (device_large) {
    DisplayMetrics metrics = new DisplayMetrics();
    Activity activity = (Activity) activityContext;
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
            || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
            || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
            || metrics.densityDpi == DisplayMetrics.DENSITY_TV
            || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
        AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-True");
        return true;
    }
}
AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-False");
return false;

}

检查是Android Tv

public static final String TAG = "DeviceTypeRuntimeCheck";

UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
    Log.d(TAG, "Running on a TV Device")
} else {
    Log.d(TAG, "Running on a non-TV Device")

}