The Android development tutorial is judged by the way the phone or the tablet _android

Source: Internet
Author: User
Tags pow

Method One

Copy Code code as follows:

public static Boolean Istablet (context context) {
Return (Context.getresources (). GetConfiguration (). screenlayout
& Configuration.screenlayout_size_mask)
>= Configuration.screenlayout_size_large;
}

Method Two

To determine whether a cell phone or a tablet is done by calculating the size of the device:

Copy Code code as follows:

/**
* To determine whether the plate
*
* @return
*/
Private Boolean Ispad () {
WindowManager wm = (WindowManager) getsystemservice (Context.window_service);
Display display = Wm.getdefaultdisplay ();
Screen width
float screenwidth = Display.getwidth ();
Screen height
float screenheight = Display.getheight ();
Displaymetrics dm = new Displaymetrics ();
Display.getmetrics (DM);
Double x = Math.pow (dm.widthpixels/dm.xdpi, 2);
Double y = Math.pow (dm.heightpixels/dm.ydpi, 2);
Screen size
Double screeninches = math.sqrt (x + y);
Pad is greater than 6 size
if (screeninches >= 6.0) {
return true;
}
return false;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.