如何在Android中检测平板电脑设备?

Sha*_*afi 4 android tablet android-layout

我试图将我为智能手机开发的应用程序移植到平板电脑上进行微小修改.Android中是否有API来检测设备是否为平板电脑?

我可以通过比较屏幕尺寸来做到这一点,但检测平板电脑的正确方法是什么?

rof*_*son 18

我不认为API中有任何特定的标志.

基于GDD 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);
}
Run Code Online (Sandbox Code Playgroud)

资源