Android to determine whether the current device is a mobile phone or tablet

Source: Internet
Author: User

Android development needs to be adapted to mobile phones and tablets, and some needs to be judged when the device is mobile or tablet.
Many on the internet say through the device size, DPI, version number, whether the telephone function, etc. to judge, but are not too accurate.
Here's a simple way to share your strength (official usage):

/**@param @return */public static Boolean Ispad (context context) {    return (Context.getresources (). GetConfiguration (). Screenlayout            & Configuration.screenlayout_size_mask)             >= Configuration.screenlayout_size_large;}

Make sure that you have a telephone function judgment method (now some tablets can also call):

 Public Static boolean Ispad (activity activity) {    Telephonymanager telephony = (Telephonymanager) Activity.getsystemservice (context.telephony_service);    if (Telephony.getphonetype () = = Telephonymanager.phone_type_none) {        returntrue;    } Else {        returnfalse;    }}

As for the device size, resolution, version number, to the current mobile phone, the individual believes that the accuracy is too poor, not recommended to use.


Other great article articles

Android Learning Notes ($) Android Options Menu and submenu (submenu) Android Learning note (notification) features and usage of Android Learning notes ($) Android using listeners to listen to menu events Android Learning notes (+) Android Create a single-selection menu and a check menu for jquery tutorials ( -ajax operations based on request load Data jquery tutorial (-ajax) append HTML for operation

more about Android Development articles


Android to determine whether the current device is a mobile phone or tablet

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.