Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correctly detect Android device type

Tags:

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

like image 746
Spotlight Avatar asked Oct 20 '16 14:10

Spotlight


People also ask

What is device type in Android?

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 .

Is a tablet an Android?

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.

What does device compatibility mean?

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.


2 Answers

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 
like image 108
MIkka Marmik Avatar answered Sep 19 '22 19:09

MIkka Marmik


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.

like image 37
A. Badakhshan Avatar answered Sep 19 '22 19:09

A. Badakhshan