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