在Java中有没有标准的方法来查找我的应用程序可以运行在哪些Android设备上(如平板电脑或手机)?
以下是代码:
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);
}
或者你可以在 AndroidManifest.xml 中设置支持的屏幕:
<manifest ... >
<supports-screens android:xlargeScreens="true" />
...
</manifest>
还有android.os.Build类。其中有许多静态常量,包括制造商和型号等。