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