Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

3.6. 判断是平板,还是手机

通过像素判断,不是太准确

		
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;
        Log.e(TAG, "width: " + width + ", height: " + height);
		
		

通过电话类型判断

		
        TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        Log.d(TAG, "Phone type: " + telephony.getPhoneType());
        if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
            Log.d(TAG, "这是平板");
        } else {
            Log.d(TAG, "这是手机");
        }