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

5

How can I tell if I'm working on a tablet or smartphone with the Android API?

Nowadays the resolutions, dpi are almost the same between tablets and smartphones and it's tricky to know which device I'm working on.

The idea is for my application to be portrait for smartphones and portrait / landscape for tablets / p>

I've seen this question but it does not solve my problem.

Is there any way to know if I'm in tablet or smartphone for sure?     

asked by anonymous 07.08.2014 / 11:48

4 answers

1

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

As I said, I was using both the large suffix and the sw-600dp suffix for layout's and features for Tablet's , the large as compatibility since sw-600dp is not recognized in versions earlier than 3.0 (Honeycomb) of Android.

However, some devices like HTC One and Xperia Z1 and others that have a 1920x1080 screen with a density of approximately 320 dpi ended up using the features and layout of the large , breaking my logic and my UI.

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

In short: Put Tablet resources with suffix sw-600dp , either landscape or portrait , not large for compatibility.

    
19.09.2014 / 19:15
1

Your answer is here

link

Link to the subject:

link

If you read the entire topic, they explain how to set 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 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>

Next, in the "standard" value file (such as res / values /), you set the boolean to false:

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

So in your activity, you can get this value and check if you're running on a tablet-sized device:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
  // do something
} else {
  // do something else
}
    
07.08.2014 / 17:12
0

Hello, I think you should even choose to "filter" by screen size and not because it is a tablet or smartphone, that is, if the screen is large even if it is not a tablet it will be fine ... Here, you should help: link

    
07.08.2014 / 11:59
0

I think you should not focus on whether it is a tablet or if it is a smartphone for behavior of your app, as said there is a smartphone that is the size or bigger than a tablet (as has been said). In my point of view it would be to set a behavior for a particular resolution, because it could happen that user is with a smartphone and you want your app to behave like a tablet because of the resolution.

Anyway, I do not know if it's right anymore and if you used css in your app with media query     [link] link

    
07.08.2014 / 15:19