Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if the device has touch screen or not

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");
like image 977
gop Avatar asked Jun 27 '13 06:06

gop


People also ask

How to detect touch screen in JavaScript?

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.


1 Answers

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.

like image 57
Anup Cowkur Avatar answered Sep 22 '22 11:09

Anup Cowkur