2012-05-28 63 views
0

我想檢查我的設備是不是平板電腦。如何實現方法isMyDeviceATablet()?

方法isMyDeviceATablet()或isMyDeviceATablet(Context context)的最佳實現是什麼?

+0

http://stackoverflow.com/questions/5832368/tablet-or-phone-android –

+0

^該帖子頂端回答似乎有點玄乎,恕我直言。 –

回答

2

從谷歌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); 
}