简体   繁体   中英

Check for Android TV box

I'm trying to differentiate between Android smartphones, tablets and TV box. 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 :

Add this line in sw720dp/dimens.xml & sw600dp/dimens.xml

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

And in 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; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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