0

How can I know the device type between tablet, phone and tv box android ? I already tried screen size with javascript but some tablet have the same screen size as a tv.

Shvet Chakra
  • 1,043
  • 10
  • 21
youneslalami
  • 7
  • 1
  • 7
  • How did you tried with javascript ? – droidev Nov 30 '15 at 17:44
  • 1
    What difference does it make if the device is a "phone", a "tablet", or a "tv box"? After all, those are marketing terms more than technical ones. What are the technical differences between these categories that concern you? – CommonsWare Nov 30 '15 at 17:51
  • To answer your question literally you can check the specific device manufacturer and model with this two different lines of code. android.os.Build.MANUFACTURER android.os.Build.MODEL This way you will know the device type. – TerNovi Nov 30 '15 at 18:23

1 Answers1

1

check is Tablet device.

private static boolean isTabletDevice(Context activityContext) {
boolean device_large = ((activityContext.getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK) ==
        Configuration.SCREENLAYOUT_SIZE_LARGE);

if (device_large) {
    DisplayMetrics metrics = new DisplayMetrics();
    Activity activity = (Activity) activityContext;
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
            || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
            || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
            || metrics.densityDpi == DisplayMetrics.DENSITY_TV
            || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
        AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-True");
        return true;
    }
}
AppInstance.getLogger().logD("DeviceHelper","IsTabletDevice-False");
return false;

}

Check is Android Tv

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")

}

Magesh Pandian
  • 8,789
  • 12
  • 45
  • 60