Android determines whether the current device is a mobile phone or tablet or an android tablet.

Source: Internet
Author: User

Android determines whether the current device is a mobile phone or tablet or an android tablet.

Android development needs to adapt to mobile phones and tablets. In some cases, it is necessary to determine whether the device is a mobile phone or tablet.
On the Internet, it is often said that the device size, DPI, version number, and whether the phone function is available are used to determine whether the device is accurate.
Here is a concise and powerful method (official usage ):

/*** Determine whether the current device is a mobile phone or tablet. The code is from Google I/O App for Android * @ param context * @ return flat and returns True, the mobile phone returns False */public static boolean isPad (Context context) {return (context. getResources (). getConfiguration (). screenLayout & Configuration. SCREENLAYOUT_SIZE_MASK)> = Configuration. SCREENLAYOUT_SIZE_LARGE ;}

To determine whether the phone function is available (you can call some tablets now ):

public static boolean isPad(Activity activity) {    TelephonyManager telephony = (TelephonyManager)activity.getSystemService(Context.TELEPHONY_SERVICE);    if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {        return true;    }else {        return false;    }}

As for the device size, resolution, and version number, I personally think that the accuracy is too poor and it is not recommended.


Other brilliant articles

Android learning notes (41) android option menu and SubMenu android learning notes (40) Functions and usage of Notification android learning notes (42) android uses a listener to listen to menu events android learning notes (43) android creates a single-choice menu and a check menu jQuery tutorial (12)-ajax operation-based request loading data jQuery tutorial (13) -ajax operation-append HTML

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.