我知道可以获得屏幕尺寸,但我想知道是否有人能够确定Android设备是否有屏幕。即它是否是机顶盒。
我认为返回的屏幕尺寸应为"零",但我不确定这是否真的是现实世界中的响应。
谢谢。
答案 0 :(得分:4)
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");
}
答案 1 :(得分:0)
在您的代码开始时粘贴此代码:
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
确定屏幕尺寸。