我正在开发一个通用 Android 应用程序,我需要检查该应用程序是否在平板电脑或手机中运行。有什么方法可以实现吗?
最佳答案
您可以查看 Google I/O App for Android源代码:
在 UIUtils类有以下方法:
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);
}
关于android - 开发通用 Android 应用程序(手机和平板电脑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6872190/