I'm developing an universal android application and I need to check if the application is running in a tablet or in a phon开发者_运维知识库e. Is there any method to do it?
You can check the Google I/O App for Android src code:
In the UIUtils class you have the following methods:
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);
}
In the sdk you can create a device with the atributes you want (screen resolution, ram, touch screen, gps .... )
That's actually an interesting question. I don't have an absolute answer, but you might find some good input here How to detect system information like os or device type
And also, TelephonyManager.getPhoneType() and other methods in TelephonyManager might be of interest.
Use Context.getSystemService(Context.TELEPHONY_SERVICE) to get an instance of TelephonyManager.
New implementation from Google Jelly Bean:
// SystemUI (status bar) layout policy
int shortSizeDp = shortSize
* DisplayMetrics.DENSITY_DEFAULT
/ DisplayMetrics.DENSITY_DEVICE;
if (shortSizeDp < 600) {
// 0-599dp: "phone" UI with a separate status & navigation bar
mHasSystemNavBar = false;
mNavigationBarCanMove = true;
} else if (shortSizeDp < 720) {
// 600-719dp: "phone" UI with modifications for larger screens
mHasSystemNavBar = false;
mNavigationBarCanMove = false;
} else {
// 720dp: "tablet" UI with a single combined status & navigation bar
mHasSystemNavBar = true;
mNavigationBarCanMove = false;
}
}
精彩评论