Well you can do it like this:
private boolean isTabletDevice() {
if (android.os.Build.VERSION.SDK_INT >= 11) { // honeycomb
// test screen size, use reflection because isLayoutSizeAtLeast is only available since 11
Configuration con = getResources().getConfiguration();
try {
Method mIsLayoutSizeAtLeast = con.getClass().getMethod("isLayoutSizeAtLeast", int.class);
Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
return r;
} catch (Exception x) {
x.printStackTrace();
return false;
}
}
return false;
}
An idea was just to check the API level, but in future the tablets and smartphones could use the same Android version (because they merged tablet version with smartphones version starting with ICS), so this is not a good idea.
The next challenge is to make the code backward-compatible with reflection, because the low level Android devices API level < 9 doesn't support the required method for checking the screen resolution.
Good luck,
Arkde