Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display.getSupportedModes() returns only 1080p display mode on 4K Android TV

Am recently adding support for 4K in my app for Android TV users. My test device is SONY KD-49XF9005. While the built-in image viewer, as well as YouTube, can display in 4K without issue, I've got no luck getting it to work for my app so far.

My app uses a GLSurfaceView to render images. I've followed the 4K Display Mode API guide, and with that I hope to be able to select one of the 4K display modes available on my TV so that my GLSurfaceView can draw in physical resolution (code snippet shown below). However, the API constantly returns me one and only one display mode i.e. 1080p. This really bothers me, the hardware should support it as other built-in apps can use 4K, why doesn't it return a 4K display mode for my app?

I've also read through all relevant Android TV developer guide and wasn't able to find anything special. I'd really appreciate if anyone can shred me some light on this. Thanks!

public static void select4kDisplayMode(Context context, Window window) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;
    }

    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Display.Mode[] modes = display.getSupportedModes();
    if (modes == null) {
        return;
    }

    Display.Mode selected = null;
    long max = 0;
    for (Display.Mode mode : modes) {
        FL.d(TAG, "available display mode: Mode %d: %dx%d/%.1ffps", mode.getModeId(),
                mode.getPhysicalWidth(), mode.getPhysicalHeight(),
                mode.getRefreshRate());
        long val = mode.getPhysicalWidth() * mode.getPhysicalHeight();
        if (val > max) {
            max = val;
            selected = mode;
        }
    }
    if (selected != null) {
        WindowManager.LayoutParams params = window.getAttributes();
        params.preferredDisplayModeId = selected.getModeId();
        window.setAttributes(params);

        FL.d(TAG, "selected display mode: Mode %d: %dx%d/%.1ffps", selected.getModeId(),
                selected.getPhysicalWidth(), selected.getPhysicalHeight(),
                selected.getRefreshRate());
    }
}
like image 294
bosphere Avatar asked Nov 07 '22 05:11

bosphere


1 Answers

I am a coder in China, I found that Android TV only support 1080p resolution to the Android App. It`s so confused me that I print the params of TV, and you can see the doc, it shows that you can render 4K video with the API in Android 6.0, but the native app only support 1080p in TV. here: android 6.0 how supports 4K

like image 78
UsherChen Avatar answered Dec 19 '22 17:12

UsherChen