Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tablet or Phone - Android

Tags:

android

tablet

People also ask

Is it better to have a phone or a tablet?

Tablets are much easier to read on and use to type. Reading and reviewing plans on a smartphone is more challenging. Additionally, typing out longer pieces of text is harder, because the screen and keyboard are smaller. Smartphones are much easier to make calls on, generally, have better internet connections.

Can an Android tablet be used as a phone?

Once you've established an internet connection, you really need only two things to make your tablet function as a smartphone: an app that makes use of VoIP (Voice over Internet Protocol) or VoLTE (Voice over LTE) wireless calling technology, and a pair of headphones.

What is the difference between Android phone and tablet?

Tablets have much larger screens than smartphones. Smartphones are more portable than tablets. Smartphones have call and SMS functionalities while many tablets do not. Some applications may only run in tablets and not smartphones.

Can my Samsung tablet be used as a phone?

Don't you hate it when your phone starts ringing once you're snuggled up and comfortable in bed? With the Call & text on other devices feature, you can make and receive calls on your tablet as long as it's signed into the same Samsung account as your phone.


As it has been mentioned before, you do not want to check whether the device is a tablet or a phone but you want to know about the features of the device,

Most of the time, the difference between a tablet and a phone is the screen size which is why you want to use different layout files. These files are stored in the res/layout-<qualifiers> directories. You can create an XML file in the directoy res/values-<same qualifiers> for each of your layouts and put an int/bool/string resource into it to distinguish between the layouts you use.

Example:

File res/values/screen.xml (assuming res/layout/ contains your layout files for handsets)

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="screen_type">phone</string>
</resources>


File res/values-sw600dp/screen.xml (assuming res/layout-sw600dp/ contains your layout files for small tablets like the Nexus 7)

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="screen_type">7-inch-tablet</string>
</resources>


File res/values-sw720dp/screen.xml (assuming res/layout-sw720dp/ contains your layout files for large tablets like the Nexus 10):

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="screen_type">10-inch-tablet</string>
</resources>


Now the screen type is accessible via the R.string.screen_type constant.


To detect whether or not the device is a tablet use the following code:

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

LARGE and XLARGE Screen Sizes are determined by the manufacturer based on the distance from the eye they are to be used at (thus the idea of a tablet).

More info : http://groups.google.com/group/android-developers/browse_thread/thread/d6323d81f226f93f


This post helped me a lot,

Unfortunately I don't have the reputation necessary to evaluate all the answers that helped me.

I needed to identify if my device was a tablet or a phone, with that I would be able to implement the logic of the screen. And in my analysis the tablet must be more than 7 inches (Xlarge) starting at MDPI.

Here's the code below, which was created based on this post.

/**
 * Checks if the device is a tablet or a phone
 * 
 * @param activityContext
 *            The Activity Context.
 * @return Returns true if the device is a Tablet
 */
public static boolean isTabletDevice(Context activityContext) {
    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & 
                        Configuration.SCREENLAYOUT_SIZE_MASK) == 
                        Configuration.SCREENLAYOUT_SIZE_XLARGE);

    // If XLarge, checks if the Generalized Density is at least MDPI
    // (160dpi)
    if (xlarge) {
        DisplayMetrics metrics = new DisplayMetrics();
        Activity activity = (Activity) activityContext;
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
        // DENSITY_TV=213, DENSITY_XHIGH=320
        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) {

            // Yes, this is a tablet!
            return true;
        }
    }

    // No, this is not a tablet!
    return false;
}

Why not calculate the size of the screen diagonal and use that to make the decision whether the device is a phone or tablet?

private boolean isTablet()
{
    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    display.getMetrics(displayMetrics);

    int width = displayMetrics.widthPixels / displayMetrics.densityDpi;
    int height = displayMetrics.heightPixels / displayMetrics.densityDpi;

    double screenDiagonal = Math.sqrt( width * width + height * height );
    return (screenDiagonal >= 9.0 );
}

Of course one can argue whether the threshold should be 9 inches or less.


there is no difference. You should define what you think is the difference, and check for that. Is a galaxy tab a phone? or a tablet? and why?

You should define what specific features you are looking for, and code for that.

It seems you are looking for 'tilt'. I think this is the same as the accelerometer (is that a word?). You can just check if the device supports it, using:

public class Accel extends Activity implements SensorListener {
...
  SensorManager sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
  boolean accelSupported = sensorMgr.registerListener(this,
        SENSOR_ACCELEROMETER,
        SENSOR_DELAY_UI);
...
}

(from http://stuffthathappens.com/blog/2009/03/15/android-accelerometer/ . i have not tested it)