How to detect a device - is it an Android phone or Android tablet?

I have two apps for Android tablets and Android phones. For the tablet app, I set android:minSdkVersion="11" . But currently, Android phones like the Galaxy S3 have Android 4.0.4, so S3 users can download the app for my tablet from the Google Play Store. I want to warn phone users to download the phone app when they install the tablet app. Conversely, tablet users download the tablet app when they launch the phone app.

Is there an easy way to determine the type of device?

Edit:

I found a solution at this link .

In your manifest file, you can declare the screen function for the phone and tablet, after which Google Play will determine the download permissions for the phone and tablet.

+55
android device-detection
Jul 04 2018-12-12T00:
source share
8 answers

Use this:

 public static boolean isTablet(Context context) { return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; } 

which will return true if the device is operating on a large screen.

Some other useful methods can be found here .

+129
Jul 04 2018-12-12T00:
source share

You can also try this.
Add the boolean parameter to the resource file.
add this line to res / values ​​/dimen.xml file

 <bool name="isTab">false</bool> 

while in res / values-sw600dp / dimen.xml the file adds this line:

 <bool name="isTab">true</bool> 

then in your java file get this value:

 if(getResources().getBoolean(R.bool.isTab)) { System.out.println("tablet"); } else { System.out.println("mobile"); } 
+20
Dec 14 '15 at 7:27
source share

This code snippet will indicate whether the device type is 7 inches or more, as well as Mdpi or higher resolution. You can change the implementation to suit your needs.

  private static boolean isTabletDevice(Context activityContext) { boolean device_large = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = (Activity) activityContext; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-True"); return true; } } AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-False"); return false; } 
+7
Sep 11 '13 at 12:16
source share

Use the capabilities of the Google Play store and allow you to download the tablet application to tablets and the phone application on phones.

If the user then installs the wrong application, then they must be installed using another method.

0
Jul 04 2018-12-12T00:
source share

We had a similar problem with our application, which should switch based on the type of device - Tab / Phone. IOS gave us a great type of device, but the same idea didn't work with Android. resolution method / DPI failed with small res tabs, high resolution phones. after a lot of torn hair and hit our head against the wall, we tried a strange idea, and it worked exceptionally well, which would not depend on the resolutions. it will help you too.

in the main class, write this and you should get your device type as null for TAB and mobile for phone.

 String ua=new WebView(this).getSettings().getUserAgentString(); if(ua.contains("Mobile")){ //Your code for Mobile }else{ //Your code for TAB } 
0
Jun 03 '14 at 13:30
source share

Use the following code to identify the type of device.

 private boolean isTabletDevice() { if (android.os.Build.VERSION.SDK_INT >= 11) { // honeycomb // test screen size, use reflection because isLayoutSizeAtLeast is only available since 11 Configuration con = getResources().getConfiguration(); try { Method mIsLayoutSizeAtLeast = con.getClass().getMethod("isLayoutSizeAtLeast"); Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con, 0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE return r; } catch (Exception x) { return false; } } return false; } 
0
Aug 19 '14 at 4:31
source share

If you want to determine if the device is a tablet or a phone with a screen diagonal, you can use the following

A device measuring 6.5 inches or larger is considered a tablet, but some recent portable phones have a larger diagonal. It’s good that with the following solution you can set the margin.

 public boolean isDeviceTablet(){ DisplayMetrics metrics = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(metrics); float yInches= metrics.heightPixels/metrics.ydpi; float xInches= metrics.widthPixels/metrics.xdpi; double diagonalInches = Math.sqrt(xInches*xInches + yInches*yInches); if (diagonalInches>=6.5) { return true; } return false; } 
0
Jul 16 '19 at 6:02
source share

I think this should detect if phonecall can do something, everything else will be a tablet / TV without phone capabilities.

As far as I saw, this is the only thing that does not rely on screens.

 public static boolean isTelephone(){ //pseudocode, don't have the copy and paste here right know and can't remember every line return new Intent(ACTION_DIAL).resolveActivity() != null; } 
-one
Sep 14 '16 at 15:05
source share



All Articles