如何确定 Android 设备是否有屏幕,即它是否是 Android 机顶盒?

How to determine if an Android device has a screen i.e. whether it is an Android set top box?

我知道可以获取屏幕尺寸,但我想知道是否有人能够查明 Android 设备是否有屏幕。即是否是机顶盒

我猜返回的屏幕尺寸应该是 "zero",但我不确定这是否真的是现实世界中的响应。

谢谢。

在开始您的代码时粘贴此代码:

    int screenSize = getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK;

String toastMsg;
switch(screenSize) {
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        toastMsg = "Large screen";
        break;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        toastMsg = "Normal screen";
        break;
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        toastMsg = "Small screen";
        break;
    default:
        toastMsg = "Screen size is neither large, normal or small";
}
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();

您可以通过 toastMsg 确定屏幕尺寸。

你可以check for a TV device.

public static final String TAG = "DeviceTypeRuntimeCheck";

UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
    Log.d(TAG, "Running on a TV Device");
} else {
    Log.d(TAG, "Running on a non-TV Device");
}