简体   繁体   English

检查 Android 电视盒

[英]Check for Android TV box

I'm trying to differentiate between Android smartphones, tablets and TV box.我试图区分 Android 智能手机、平板电脑和电视盒。 Is there any way to check that on which device type app is running ?有没有办法检查正在运行哪种设备类型的应用程序?

Yes, you can use following method to detect type of device :是的,您可以使用以下方法检测设备类型:

  1. Add a bool in dimension's files to detect Tablet :在维度文件中添加 bool 以检测 Tablet :

Add this line in sw720dp/dimens.xml & sw600dp/dimens.xml在 sw720dp/dimens.xml & sw600dp/dimens.xml 中添加这一行

<bool name="isTablet">true</bool>

And in values/dimens.xml.并在 values/dimens.xml 中。 make it false :使它成为假:

<bool name="isTablet">false</bool>
  1. Add this method, and use booleans to detect type :添加此方法,并使用布尔值来检测类型:

     boolean isTablet; boolean isAndroidTv; isTablet = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; if (!isTablet) { isTablet = context.getResources().getBoolean(R.bool.isTablet); } UiModeManager uiModeManager = (UiModeManager) (context.getSystemService(UI_MODE_SERVICE)); if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) { isAndroidTv = true; } else if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEVISION) || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { isAndroidTv = true; } else if (!context.getPackageManager().hasSystemFeature("android.hardware.touchscreen")) { isAndroidTv = true; } else if (!context.getPackageManager().hasSystemFeature("android.hardware.telephony")) { isAndroidTv = true; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM