How do I know if it’s a tablet or a smartphone?

Asked

Viewed 1,387 times

5

How do I know I’m working on one tablet or a smartphone with the Android API?

Nowadays resolutions, dpi are almost the same thing between tablets and smartphones and it gets complicated to know which device I’m working on.

The idea is that my app Portrait for smartphones and Portrait/Landscape for tablets.

I’ve seen it before this issue but it doesn’t solve my problem.

Is there any way to know if I’m in tablet or smartphone for certain?

  • Nowadays there are smartphones that are bigger than some tablets, old or not. That is, the difference between concepts of tablets and smartphones is getting very blurry, so you should choose another parameter to be based, such as screen size (yes, in inches)

  • How do I get to that size?

  • I have no idea, I’m just telling you a possibility of how to solve your problem ;)

  • Jorge, I usually use the "suffix" large (p.and: values-large) in my Sources. But I no longer have the compleeeta certainty if it will not give false positives (Type a Galaxy note 3 of life or LG G3). Now I feel like testing...

  • Test and tell me :D I’ve never put much stock in these suffixes.

  • I tested now, in GN3 the large didn’t take, which is acceptable. Using my Nexus 7, it works. In Android Guideline, he talks about sw600-xx for tablets of 7", sw720-xx for tablets of 10" and also comments about xlarge. Try taking a look at these 3 to see if it answers.

  • My problem is that my app has to work everywhere, but on smartphones it only works on Portrait.

  • @Wakim I’m experimenting with Sony Xperia z and is taking over as a tablet :(

  • @Jorgeb. I tested with this Sony Xperia Z (same screen size and same dpi as GN3) and it worked. There is also Sony Xperia Tablet Z. Remembering that I use the layout-large for example.

  • @Wakim Worked out like that? Assumed large? Or not?

  • Assumed as not in Xperia.

  • And in the m705f? That to me assumes me as not large :(

Show 7 more comments

4 answers

1

Your answer is here

https://stackoverflow.com/questions/9279111/determine-if-the-device-is-a-smartphone-or-tablet

Link to the subject:

http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali

If you read the whole topic, they explain how to define a boolean value in a specific value file (such as res/values-sw600dp/);

<resources>
    <bool name="isTablet">true</bool>
</resources>

Because the sw600dp qualifier is only valid for the above android 3.2 platforms. If you want to make sure that this technique works on all platforms (before 3.2), create the same file in the res/ values-xlarge folder:

<resources>
    <bool name="isTablet">true</bool>
</resources>

Then, in the "standard" value file (as res/values/), you set the Boolean to false:

<resources>
   <bool name="isTablet">false</bool>
</resources>

Then on your Activity, you can get this value and check if you are running on a tablet-sized device:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
  // do something
} else {
  // do something else
}
  • I used it assumed mine tablet as telephone.

1


As this question is interesting and this issue of correctly identifying Tablet’s brought me problems too, I managed to solve. I leave my solution to the problem:

Like I said, I was using both the suffix large how much the suffix sw-600dp for’s layout and features for Tablet’s, the large as compatibility since the sw-600dp is not recognized in versions prior to Android 3.0 (Honeycomb).

But some Vices like the HTC One and the Xperia Z1 and others that have screen 1920x1080 with density of approximately 320 dpi ended up using the resources and layout’s of the suffix large, breaking my logic and my UI.

My solution was to abolish the use of the suffix once and for all large, given that looking at the Dashboard platform, no relevant data on the use of Honeycomb (3.0) and on my Dashboard Google Play appears 0.46% of users totals (not just my app), so I decided to ignore to not cause detriment to other users of more modern devices.

Summarizing: Put the Tablet features with suffix sw-600dp, be it landscape or portrait and not in large compatibility.

  • And you pick up all the tablets with that suffix and no smartphone?

  • I tested this qualifier sw600dp in that Xperia and it worked. The problem was the large that I had left as compatibility.

  • The problem is that I have a Chinese tablet with 320dp and will be screwed for sure. I solved the problem otherwise, but was gambiarra.

  • Ah, I didn’t think of them because I can’t test them. The problem is that making a rule just for them might end up encompassing a high end phone. If you can test the sw320dp on it and on an Xperia or Galaxy Note emulator.

  • It will mess up for sure. I have here this tablet and a smart Samsung Express, both with 320dp. There’s my problem.

  • But this seems to be the best answer for MOST devices.

Show 1 more comment

0

  • What do you mean by screen size? The inches?

  • Using getsize(), there are several examples http://stackoverflow.com/questions/1016896/how-to-get-screen-dimensions http://stackoverflow.com/questions/15055458/detect-7-inch-and-10-inch-tablet-programmatically

  • On this issue the screen size is miscalculated!

0

I think you should not focus on whether it is a tablet or whether it is a smartphone for a behavior of your app, because as it was said there is a smartphone that is the size or larger q a tablet (as it has already been said). In my view it would set a behavior for a certain resolution, because it may occur that the user is with a smartphone and you want your app to behave like a tablet, because of the resolution.

Anyway, I don’t know if it’s right anymore and if you used css in your app with media query [link]https://stackoverflow.com/questions/17102161/how-to-use-media-queries-for-android-devices-with-android-version-2-2-1-and-2-3

  • It is really obligatory that it is so, because Landscape on mobile phone, even the biggest ones is horrible. And on tablets even the smallest ones is good.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.