How can I check if an app is running on an Android TV

前端 未结 4 1169
太阳男子
太阳男子 2021-02-07 06:29

Is there a way to check if an app is running on an Android TV or Android Mobile?

I know how to check the running build. I want to start a specific service if the app is

4条回答
  •  日久生厌
    2021-02-07 06:59

    From Handling TV Hardware in Android Docs:

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

提交回复
热议问题