How to detect if a device has a touch screen in Titanium?


I'm targeting Android with Titanium. How can I tell if a device has a touch screen or not?

The easiest way is to test for touch event support. If they are supported, likely the device has a touch screen. If not, it probably doesn't or you can't use them anyway. One solution is:

var touchSupported = ('ontouchstart' in window);

But be careful as the browser may support touch events but the device might not (e.g. Chrome 20 supports lots of touch events in devices that don't have touch).

You may be able to get users to click a button and see if a touch event is dispatched or just a click.