如何找出运行我的应用程序的Android设备?

时间:2011-11-01 10:20:36

标签: android

Java中是否有标准方法可以找出我的应用程序将运行哪些Android设备(如平板电脑或手机)?

2 个答案:

答案 0 :(得分:3)

这是代码:

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>

如果您想了解更多详情,请访问Google IO 2011官方源代码here

我希望它有所帮助!

答案 1 :(得分:0)

还有android.os.Build类。有许多静态常数,包括制造商和模型等。