Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect device is Android phone or Android tablet?

I have two apps for Android tablets and Android phones. For tablet app I set android:minSdkVersion="11". But nowadays Android phones like Galaxy S3 has Android version 4.0.4 so S3 users can download my tablet app from Google Play Store. I want to warn phone users to download phone app when they install tablet app. Vice versa for tablet users download tablet app when they run phone app.

Is there any easy way to detect the device type?

Edit:

I found solution on this link.

In your manifest file you can declare screen feature for handset and tablets then Google Play decides download permissions for both phone and tablet.

like image 734
KAPLANDROID Avatar asked Jul 04 '12 13:07

KAPLANDROID


People also ask

How do you know if your device is Android?

On your device, go to the Home screen (the one with all the icons), and tap on the Settings icon. Scroll down and tap on About phone or About tablet. Some information will appear. If one of the lines of information says Android with a version number, you have an Android device.

How do I know what Android tablet I have?

Open 'Settings' and then 'About tablet' on the bottom left side. Then you will find 'Device name' (e.g. “Galaxy Tab A (2016)”) and 'Model number' (e.g. “SM-T585”) below. After choosing 'Software information', you'll see the 'Android version' (e.g. “7.0”).

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.


2 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 helpful methods can be found here.

like image 194
Alex Lockwood Avatar answered Oct 11 '22 17:10

Alex Lockwood


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

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

while in res/values-sw600dp/dimen.xml file add 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"); } 
like image 39
Bhavana Vadodariya Avatar answered Oct 11 '22 17:10

Bhavana Vadodariya