Is there any a way to precisely detect the device type (phone, tablet, watch, TV, auto, PC)?
Right now, I found a way to detect if the app is running on a car (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR
), on a TV (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION
), or on a watch (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_WATCH
). Is it correct? Does a phone connected to a car appears as a phone or as "Android Auto"?
To differentiate between a phone, tablet or computer I can check for the minimum screen size (600dp to qualify as tablet or laptop for example).
The problem now is to differentiate between a tablet and a laptop. Have you got any idea?
PS: I'm not asking this to make a responsive UI, it's a question related to the device management for an account
android.service.controls.DeviceTypes. Device types for Control . Each Control declares a type for the device they represent. This type will be used to determine icons and colors. The type of the device may change on status updates of the Control .
An Android tablet is a tablet-sized PC that runs on Google's Android operating system (OS). Android tablets include almost all the key features found in a regular tablet PC, including office applications, games, Web browsers and many other programs.
Because Android is an open source project, any hardware manufacturer can build a device that runs the Android operating system. Yet, a device is "Android compatible" only if it can correctly run apps written for the Android execution environment.
You can detect using this code application running on large screen or not.
public static boolean isTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; }
This link would be also helpful to you.
Get Width of screen and check that with this break-points.
/* Tablet (portrait and landscape) ----------- */
min-device-width : 768px max-device-width : 1024px
/* Desktops and laptops ----------- */
min-width : 1224px
To differentiate between a phone and a tablet or computer I can check for the minimum screen size (600dp to qualify as talet or laptop for example).
There is a better way to do that and it's using values. For example, if you have 2 type of devices (say phone and tablet), create two folder for values too. Then for values folder add this:
<resources> <bool name="isLarge">false</bool> </resources>
and in your values-large folder:
<resources> <bool name="isLarge">true</bool> </resources>
Then in your activity:
boolean isLarge = getResources().getBoolean(R.bool.isLarge); if (isLarge) { // do something } else { // do something else }
Using this, you can do same thing for phone, sw-600dp, sw-720dp and etc. I'm not sure if you can use this for TV and etc, but I think it worth to try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With