Tablet or Phone - Android

Determine if the device is a smartphone or tablet?

This subject is discussed in the Android Training:

Use the Smallest-width Qualifier

If you read the entire topic, they explain how to set a boolean value in a specific value file (as res/values-sw600dp/attrs.xml):

<resources>
<bool name="isTablet">true</bool>
</resources>

Because the sw600dp qualifier is only valid for platforms above android 3.2. If you want to make sure this technique works on all platforms (before 3.2), create the same file in res/values-xlarge folder:

<resources>
<bool name="isTablet">true</bool>
</resources>

Then, in the "standard" value file (as res/values/attrs.xml), you set the boolean to false:

<resources>
<bool name="isTablet">false</bool>
</resources>

Then in you activity, you can get this value and check if you are running in a tablet size device:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
// do something
} else {
// do something else
}

How to find Tablet or Phone in Android , Programmatically?

Try this

    public boolean isTablet(Context context) {
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}

It will return true if you are using a tablet. It has been checked on Samsung Galaxy Tab 7" and Samsung Galaxy S3.

How to detect device is Android phone or Android tablet?

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");
}

Difference between developing for smartphone / tablet?

One of the best answers is from what you'll find on developer.android.com

Each screen size offers different possibilities and challenges for
user interaction, so in order to truly satisfy and impress your users,
your application must go beyond merely supporting multiple screens: it
must optimize the user experience for each screen configuration.

Usually the programming is the same the only change is layout and maybe a few extra buttons or less buttons.

Programatically determining whether device is a Phone or Tablet

You could simply define a resource in your strings.xml file

In values/strings.xml.

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

In values-w900dp/string.xml

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

Access this resource from any where in your code. This should solve your issue.

For example :

 boolean isTablet = getResources().getBoolean(R.bool.is_tablet);

How to know if tablet or phone in Android

You can do this:

val configuration = LocalConfiguration.current
val expanded = configuration.screenWidthDp > 840

This corresponds to 97.22% of tablets in landscape. For sizes corresponding to phones or tablets there is more info here.



Related Topics



Leave a reply



Submit