Detecting display programmatically in Android app
#1
Hi,

I'm wondering if anyone who has worked on Kodi for Android could be able to point me in the right direction for a problem I'm having.

I'm developing a video playing app on a Minix X8 Plus that runs on Kodi for Android.

I'm trying to detect the display connected via an HDMI connection. The Minix device has no built in display. Whenever I use the normal Android methods for getting information about the display, I get back "Built-in display" for the display name, and 1920 x 1080 for the display size, regardless of whether a display is currently plugged into the HDMI port.

These Android methods are

DisplayManager displayManager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
Display[] displays = displayManager.getDisplays();

Display display = getWindowManager().getDefaultDisplay();



The behavior remains consistent whether or not the HDMI Auto Detect is turned on under the display portion of the settings on the device.

I have also registered a BroadcastReceiver to listen for the action "android.intent.action.HDMI_PLUGGED", and I'm not getting any response off of that when the HDMI cable is plugged / unplugged.

I'd be really appreciative if anyone involved with Kodi could point me in the right direction as how to detect the HDMI display from an Android app using Java.

If it makes any difference, this app is running at system level.

Thanks much,

Jeff
Reply
#2
The pixel display size will always be constant on Android, whichever display is hooked up.
6.0 will have a api function to detect the "real" size of the display (can't remember what/where).

At least for some device, there is a hack to get it via the "sys.display-size" system property (see https://github.com/xbmc/xbmc/blob/Isenga...id.cpp#L72)

Obviously, if you are targeting a single device, you can most probably obtain this info from sysfs.
Reply
#3
@Koying - thank you! I found a way to detect the HDMI connection through sysfs. The Minix didn't have the "sys.display-size" property, but I am getting the "real" display size that you wrote about like this:

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);

Hopefully it will return the real display size when I am able to hook it up to a 4K monitor.

Jeff
Reply

Logout Mark Read Team Forum Stats Members Help
Detecting display programmatically in Android app0