How to differentiate Android tablet, TV, cell phone

Source: Internet
Author: User

There are a number of ways to differentiate between tablets and phones before Android TV is present:

Method 1: See if there is a call function

1  Public BooleanIstabletdevice () {2Telephonymanager telephony =(Telephonymanager) Mcontext.getsystemservice (context.telephony_service);3         intType =Telephony.getphonetype ();4         if(Type = =Telephonymanager.phone_type_none) {5LOG.I ("is tablet!");6}Else {7LOG.I ("is phone!");8         }9         return false;Ten}

Method 2: By judging the screen size, this method is considered to be larger than 6 inches of the flat plate (not very reliable, one day there will be more than 6 inches of the appearance of mobile phones)

1 /**2 * detection is flat (TV) or mobile phone3       * @return4       */5      Private BooleanIspad () {6          7Displaymetrics DM =Newdisplaymetrics ();8 Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);9          intWidth=Dm.widthpixels;Ten          intheight=Dm.heightpixels; One          intdens=dm.densitydpi; A          DoubleWi= (Double) width/(Double) Dens; -          DoubleHi= (Double) height/(Double) Dens; -          Doublex = Math.pow (wi,2); the          Doubley = Math.pow (hi,2); -Commonutils.logwuwei (Tag, "width is" +wi+ "height is" +hi); -          DoubleScreeninches = Math.sqrt (x+y); -           +Commonutils.logwuwei (Tag, "screeninches is" +screeninches); -           +         //msgutils.sendsinglemsg (Splash.handlertools, "Screeninches is" +screeninches, handlerutils.show_normal_toast); A           at          //larger than 6 size is pad -          if(Screeninches >= 6.0) { -           return true; -          } -           -          return false; in         } -  to      

Now the appearance of the tablet phone, but also let the method 2 no longer used.

Back to the nature of the problem, why differentiate between tablets and mobile phones?

The purpose of the distinction is to differentiate between the best user experience for different devices, so it is understandable that Android devices larger than 6 inch are treated as tablets.

How to differentiate Android tablet, TV, cell phone

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.