我该如何实现方法isMyDeviceATablet()?

时间:2012-05-28 04:36:48

标签: java android

我想查看我的设备是否是平板电脑。

方法的最佳实现是什么isMyDeviceATablet()或isMyDeviceATablet(Context context)?

1 个答案:

答案 0 :(得分:2)

来自Google I / O 2011应用:

public static boolean isHoneycomb() {
    // Can use static final constants like HONEYCOMB, declared in 
    // later versions of the OS since they are inlined at compile 
    // time. This is guaranteed behavior.
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}

public static boolean isTablet(Context context) {
    return (context.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK)
            >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

public static boolean isHoneycombTablet(Context context) {
    return isHoneycomb() && isTablet(context);
}