Is there a way to check if the user is using a tablet or a phone? I\'ve got problems with my tilt function and my new tablet (Transformer)
The other answers list many ways of programmatically determining whether the device is a phone or tablet. However, if you read the documentation, that is not the recommended way to support various screen sizes.
Instead, declare different resources for tablets or phones. You do this my adding additional resource folders for layout
, values
, etc.
For Android 3.2 (API level 13) on, add a sw600dp
folder. This means the smallest width is at least 600dp, which is approximately the phone/tablet divide. However, you can also add other sizes as well. Check out this answer for an example of how to add an additional layout resource file.
If you are also supporting pre Android 3.2 devices, then you will need to add large
or xlarge
folders to support tablets. (Phones are generally small
and normal
.)
Here is an image of what your resources might like after adding an extra xml files for different screen sizes.
When using this method, the system determines everything for you. You don't have to worry about which device is being used at run time. You just provide the appropriate resources and let Android do all the work.
Notes