Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 running on an Android TV vs Mobile. Was hoping to house the two under the same library.

like image 683
leafartist Avatar asked Sep 02 '25 15:09

leafartist


2 Answers

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");
}
like image 143
ms_b Avatar answered Sep 05 '25 16:09

ms_b


private boolean isDirectToTV() {
  return(getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION)
      || getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK));
}

This will return true if the device is advertising itself as having either the android.hardware.type.television or android.software.leanback system features. Android TV and Fire TV handle this correctly; I have not tried it on other environment as yet.

like image 40
CommonsWare Avatar answered Sep 05 '25 15:09

CommonsWare