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 ?
Asked
Active
Viewed 555 times
-3
-
Possible duplicate of [Is there a unique Android device ID?](https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id) – Exceptional NullPointer Jul 15 '19 at 08:31
1 Answers
0
Yes, you can use following method to detect type of device :
- 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>
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; }

NehaK
- 2,639
- 1
- 15
- 31