My app runs on standard phones but it also runs on Android players which I connect via HDMI to my TV and work with a mouse to navigate. Is there a way to programatically deterrmine whether the device has touch screen support so I can distinguish between the two ways of navigation?
I tried this, but it returns true on both devices:
getPackageManager().hasSystemFeature("android.hardware.touchscreen");
One way to check for a touch screen device is to check for the window. ontouchstart method and the navigator. maxTouchPoints property. ontouchstart lets us assign a touch event listener to it that runs when we start touching the screen.
PackageManager will refer to the Android player itself which probably has a touchscreen. It cannot detect if the player display is being routed to an external monitor via HDMI. When you ask the package manager if the device has a touchscreen, it is referring to the player and not the external display.
One thing you could do is to detect if the player is connected to an external display by checking if HDMI port is active and change your navigation accordingly.
See: Detect HDMI Port in android device
Side note: If the player does not have a touchscreen but the package manager is wrongly reporting that it does, then it's either a bug with package manager or the device manufacturers implementation of Android might be buggy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With