0

I am developing a webapp that will be deployed on various devices, ranging from desktops, to Android mobiles, to Blackberry mobiles. Having to support such different devices, two different interfaces exist: touch and not touch.

The problem is that Blackberry devices without touch support, such as the Blackberry 9300, incorrectly appear to support touch events. Namely,

'ontouchstart' in window;

returns true.

Until now, I just relied on browser sniffing, as bad as it is:

if (window.navigator.userAgent.match(/BlackBerry/i)) {
    doStuff();
}

But now I have to support the Blackberry Torch, which is touch, so the latter will not work anymore. Of course I could try a more precise regex for browser sniffing, but I feel I am going down the way of perdition.

Is there a more reliable way to detect support for touch events, that will work on Blackberry devices too?

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Andrea
  • 20,253
  • 23
  • 114
  • 183

1 Answers1

0

I'm not aware of any built-in property to detect touch support but you can use device names to separate the two cases:

public boolean hasTouchScreen()
{
   if (DeviceInfo.getDeviceName().startsWith("95")){
      return true;
   }
   else if (DeviceInfo.getDeviceName().startsWith("93")){
      return false;
   }...//other devices
    ...
   else{
      return false;
   }
}

It's a pretty uncivilized way of going about it but it would still work.

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45