Share the post "How To Detect If Device is Android Tablet Or Smartphone"
The best and easiest way to have your app determine if the device is a smartphone or a tablet is to place a boolean value in a specific value file such as res/values-xlarge.
|
1 2 3 |
<resources> <bool name="isTablet">true</bool> </resources> |
Then, in the folder res/values, you can add the same XML code but with a false value.
|
1 2 3 |
<resources> <bool name="isTablet">false</bool> </resources> |
In your Android code, you can get the value with this code:
|
1 2 3 4 5 |
boolean isTablet = getResources().getBoolean(R.bool.isTablet); if (isTablet) System.out.println("this is a tablet!"); else System.out.println("this is not a tablet!"); |