I am trying to read the real physical display resolution on my Android TV device. I have two testing TVs:
- FullHD with 1920 x 1080 resolution
- UHD with 3840 x 2160 resolution
and 1 Android TV HDMI stick with Android 9.
I would like to read out the real physical screen resolution depending on the TV device. For this I tried reading out the displayMetrics in 2 ways:
attempt:
context.resources.displayMetrics
attempt:
val displayMetrics = DisplayMetrics() activity.display?.getRealMetrics(displayMetrics)
Unfortunately, my UHD device shows me 1920x1080 for both mentioned attempts. I am not interessted in some scaled down display resolution.
EDIT: As @IanGClifton answered I tried it with DisplayCompat
. I have a AndroidTV "Stick" running on Andorid 9 which is plugged to any TV (plugged into the above mentioned UHD TV with 3840x2160 px) device via HDMI. I flash the Stick and the physicalWidth
and physicalHeight
still tell me 1920x1080 pixels.
val defaultDisplay = activity.windowManager.defaultDisplay
val mode = DisplayCompat.getMode(context, defaultDisplay!!)
Log.d(TAG, "Resolution ${mode.physicalWidth} x ${mode.physicaHeigth}.")
But, when I flash the Android TV device (not the Android TV stick) directly, I get proper resolution.
How can I read out the real native physical display resolution in pixels for any devices?
Android TV currently maps the UI to 1920x1080 and then scales based on the attached panel, so you don't want to look at DisplayMetrics and instead check out DisplayCompat.
Use DisplayCompat.getSupportedModes() to get the ModeCompat objects that can tell you the resolution, but you'll need to make sure you're using a relatively recent version of AndroidX Core since there was a fix in core 1.5.0-beta02 for some panels that were incorrectly reporting 1920x1080.