Detecting 4x UHD screens on Android

I am trying to detect when a device can output with a resolution of 4K UHD (3840x2160). A number of devices, such as nVidia Shield TV and Sony Xperia Z5 Premium, will report that they work at 1080p speed, even if they are capable of UHD, because by default they have a 1080p signal output for layouts without video. I need to somehow determine if they are 4K capable in order to distinguish them from non-4K devices such as the Nexus Player.

Here is the code that I use to determine the current resolution:

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); 

On the Shield TV screen, this returns 1920x1080 all the time, even when ExoPlayer reports that it outputs video at 3840x2160.

+7
android android tv
source share
1 answer

UPDATE: this has been fixed since ExoPlayer 1.5.1 (see https://github.com/google/ExoPlayer/commit/79055066813123c939c29e5a5e223a5ff043b91e )


I continued with ExoPlayer developers and found the answer:

The only way to reliably detect 4K devices is to use Device.Mode , which is only available in api level 23+. Check out the Android M Note:

https://developer.android.com/preview/api-overview.html#4K-display

And the documentation for the class is here:

https://developer.android.com/reference/android/view/Display.Mode.html#getPhysicalWidth ()

As for ExoPlayer , it does not implement this code since the current version (1.4.2), but that is likely to change. Cm:

https://github.com/google/ExoPlayer/issues/800

And finally, to answer the question, the correct way to detect 4K now looks something like this:

 /** * Used to check if the connected device support UHD (3840x2160) * * Note that this call will fail to identify UHD devices on api level bellow 23 (M) * * @return 1 if device is UHD, 0 otherwise */ public int isUHD(){ Display display = getActivity().getWindowManager().getDefaultDisplay(); Point displaySize = getDisplaySize(display); return (displaySize.x >= 3840 && displaySize.y >= 2160) ? 1 : 0; } /** * Convenience function that forks to the different ways to obatin the Display size across Android versions * * @param display Display instance to obtain information from * * @return Point a Point describing the Display size */ private static Point getDisplaySize(Display display) { Point displaySize = new Point(); if(Util.SDK_INT >= 23){ getDisplaySizeV23(display, displaySize); }else if(Util.SDK_INT >= 17) { getDisplaySizeV17(display, displaySize); } else if(Util.SDK_INT >= 16) { getDisplaySizeV16(display, displaySize); } else { getDisplaySizeV9(display, displaySize); } return displaySize; } @TargetApi(23) private static void getDisplaySizeV23(Display display, Point outSize){ Display.Mode[] modes = display.getSupportedModes(); if(modes.length > 0){ Display.Mode mode = modes[0]; outSize.x = mode.getPhysicalWidth(); outSize.y = mode.getPhysicalHeight(); } } @TargetApi(17) private static void getDisplaySizeV17(Display display, Point outSize) { display.getRealSize(outSize); } @TargetApi(16) private static void getDisplaySizeV16(Display display, Point outSize) { display.getSize(outSize); } private static void getDisplaySizeV9(Display display, Point outSize) { outSize.x = display.getWidth(); outSize.y = display.getHeight(); } 

Which will give incorrect results on api less than 23.

+3
source share

All Articles