0

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

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

4

1 回答 1

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);
}
于 2012-05-28T04:38:53.440 回答