[英]How to determine if an Android device has a screen i.e. whether it is an Android set top box?
I know one can obtain screen sizes, but I would like to know if someone has ever been able to find out if the Android device has a screen or not. 我知道可以获得屏幕尺寸,但我想知道是否有人能够发现Android设备是否有屏幕。 ie whether it is a set top box or not. 即是否是机顶盒。
I guess screen size returned should be "zero", but I am not sure if that is actually the response in the real world. 我猜测返回的屏幕尺寸应为“零”,但我不确定这是否真的是现实世界中的响应。
Thank you. 谢谢。
You can 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");
}
In staring of your code paste this code: 在盯着您的代码粘贴此代码:
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();
you can determine screen size by toastMsg
. 您可以通过toastMsg
确定屏幕大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.