Search code examples
androidandroid-hardware

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. i.e. 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.


Solution

  • 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");
    }