You can check if your app is running on different versions of Android using the following:
int sdk = Build.VERSION.SDK_INT;
if (sdk <= Build.VERSION_CODES.ECLAIR){
//do stuff
} else {
//do some other stuff
}
Is there such a check for tablet use? Currently I have two ways to find out that I don't like:
Configuration configuration = getResources().getConfiguration();
if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
try {
return configuration.screenWidthDp >= 1024;
} catch (NoSuchFieldError ex) {
return false;
}
} else {
return false;
}
And, if I use a different layout file with different view ids:
return findViewById(R.id.mytabletlinearlayout) == null;
Is there something like the version codes available for this? Or is there another more elegant solution?
Edit
For some clarity, I need to perform some different actions if I'm running my app on a tablet, because then I am using a multi-pane layout.