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

前端 未结 4 1117
太阳男子
太阳男子 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 07:03

    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.

提交回复
热议问题