1

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:

  1. attempt:

     context.resources.displayMetrics
    
  2. 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?

Edna Krabappel
  • 362
  • 1
  • 2
  • 16
  • `some scaled down display resolution.` Ar you shure the other one is not scaled up? – blackapps Jun 08 '21 at 09:10
  • @blackapps The FullHD shows 1920x1080. The UHD TV shows also 1920x1080. So wich one is supposed to be scaled up?!? – Edna Krabappel Jun 08 '21 at 09:18
  • The 3840 x 2160 of course. – blackapps Jun 08 '21 at 09:18
  • @blackapps It is a real UHD device with native display of 3840x2160. I can watch 4K movies on the UHD TV. The launcher app runs under 1920x1080 I guess, which is the reason I get 1920x1080 on the UHD device. I dont get your point? – Edna Krabappel Jun 08 '21 at 09:28
  • Are you using the conversion from dips to pixels: https://developer.android.com/training/multiscreen/screendensities#dips-pels and https://developer.android.com/reference/android/util/DisplayMetrics#DENSITY_XXXHIGH – Morrison Chang Jun 08 '21 at 11:04
  • I have my AndroidTV stick plugged into a 3440 x 1440 gaming monitor. There I have black bars on the side and thus the same problem. I wouldl like to read devices real physical native possible resolution. – Arsene Raul Jun 14 '21 at 07:02

1 Answers1

0

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.

Ian G. Clifton
  • 9,349
  • 2
  • 33
  • 34
  • I tried DisplayCompat and it did not work. I added androidx lib from gradle in OP. Seem like I dont use core explicitly? – Edna Krabappel Jun 11 '21 at 11:55
  • getSupportedModes.size show 5 but iterating with forEach show 2 onyl. Both still have 1920x1080 . I used androidx.core:core:1.6.0-beta02 – Edna Krabappel Jun 13 '21 at 20:13
  • DisplayCompat works on Android TV devices , but not on Android TV sticks (like fireTV stick) – Edna Krabappel Jun 14 '21 at 13:40
  • DisplayCompat.getSupportedModes() returns an array, so forEach should iterate over it exactly the same number of times as the size property. I'd have to see the code to have a guess why you're seeing that behavior. You should be able to do `DisplayCompat.getSupportedModes(context, display).any { it.physicalWidth >= 3840 && it.physicalHeight >= 2160 }` to verify if the screen is at least 4k. That said, I've only used it on Android TV. If you're now talking about a FireTV Stick, that does not run Android TV, and I don't know if it reports sizes in the same way. – Ian G. Clifton Jun 15 '21 at 00:08
  • I am sorry, it's not a FireTv Stick. It's a similar stick, but that stick has definetly running Android API 28 = 9 on it. – Edna Krabappel Jun 15 '21 at 07:45
  • Ah, my misunderstanding :) If it's running Android TV, DisplayCompat should work. I'd first verify that the stick itself supports 4k. If so, then you can also try plugging the stick in to the TV but keep it turned off, turn the TV on and switch to the HDMI port the stick is in, then turn on the stick. Some devices don't support hotswapping, so that can also be an issue. Looks like you already filed a bug for it, but be sure to add a full bugreport to make it easier for the engineers to track down. – Ian G. Clifton Jun 16 '21 at 23:19
  • According to this commits comment from Brian Lindahl: https://android.googlesource.com/platform/frameworks/support/+/6af7da26568024e627cfe3b392c2057eb33e101a. "We've learned a lot about Android TV architecture in this area over the last year and the original concept is flawed. HDMI offers no way to determine what the 'native' mode is." – Edna Krabappel Jun 17 '21 at 07:50