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.
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");
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With