1

I heard that there is a keyword or method that Android developers can use to determine whether Android 4.0+ is running on a tablet (without having to do any kludgy screen size comparisons). I can't find it.

So, is this true? If so, what is it?

Edit: I see that people are giving me answers that are not what I'm looking for. I already know how to determine whether a device is a tablet or phone using the kludgy screen size method and using the OS method. I'm looking for a method that has been available starting with API level 14 that will tell me the same information -- hopefully. I can't find it, so I'm wondering whether it even exists.

Jay Namon
  • 147
  • 1
  • 8

3 Answers3

1

Tablet basically just means a big(er) screen, so it comes down to that. There's an easy way of seeing if it's a tablet sized screen or not:

if ( getResources().getConfiguration().isLayoutSizeAtLeast( Configuration.SCREENLAYOUT_SIZE_XLARGE ) )
{
    //Is a tablet.
}

You could change Configuration.SCREENLAYOUT_SIZE_XLARGE to Configuration.SCREENLAYOUT_SIZE_LARGE if you want to catch smaller ones too.

Khantahr
  • 8,156
  • 4
  • 37
  • 60
  • 1
    I actually explicitly asked for the capability in Android 4+. I also explicitly said that I didn't want the solution that involves screen size comparisons. – Jay Namon Oct 19 '12 at 18:22
  • You said you didn't want "kludgy" screen size comparisons. Though "kludgy" is subjective, most people would probably agree that this method is not "kludgy." Android 4+ is capable of doing this. If you also want to know if it is Android 4+, then you can do `if ( android.os.Build.VERSION.SDK_INT >= 14 )`. – Khantahr Oct 19 '12 at 18:27
0

As described in the android documentation, the SDK level (integer) the phone is running is available in:

android.os.Build.VERSION.SDK_INT;

The enum corresponding to this int is in the android.os.Build.VERSION_CODES class.

Code example:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){
    // Do something for froyo and above versions
} else{
    // do something for phones running an SDK before froyo
}

Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).

Link

Community
  • 1
  • 1
Md Abdul Gafur
  • 6,213
  • 2
  • 27
  • 37
0

Android 4+ has the configuration object. You can use the "isLayoutSizeAtLeast(int size)" method to do your check. It's less kludgy than some other examples I've seen around.

Billdr
  • 1,557
  • 2
  • 17
  • 30
  • This is closer to the answer that I'm looking for – Jay Namon Oct 19 '12 at 18:32
  • That's exactly the same as what I posted, and it's been available since API 1, though the specific method was introduced in 11 (Android 3.0). – Khantahr Oct 19 '12 at 18:37
  • Ralgha's right, this is the same answer. If I remember he beat me to it by 2 minutes (his post went up while I was finding the link). – Billdr Oct 22 '12 at 12:11