9

I'm currently on a project that needs to detect whether or not a device can make a phone call. Depending on whether or not it can, I need to switch views and apply two different functions, one is a button to make a call to a particular number using tel: on html, the other is a button for you to enter your number and we'll call you using fonality.

Currently, I've managed to install such plugins/libraries such as wurfl or terawurfl, none which seems to have a 100% reliable way to detect whether the mobile phone or tablet/desktop can make a phone call.

Is there any server side or user side solution to this like a tag that I missed in wurfl/terawurfl or even a javascript ajax call that I could make to detect "yes tel: works" or something of that nature.

Kara
  • 6,115
  • 16
  • 50
  • 57
  • might not answer your question, but please have a look at this trick: http://stackoverflow.com/questions/836777/how-to-detect-browsers-protocol-handlers – Dreaded semicolon Jul 12 '12 at 07:42
  • No; JavaScript's limited to the browser, it has no way of accessing the protocol or associated handlers. You'd have to offer the choice to your user ('If you have Skype, or this is a phone, and you'd like to place the call click the "call this number" link, otherwise click the "we\'' call you" button.'). – David Thomas Jul 12 '12 at 08:22
  • 1
    I really think you should rethink your approach. Even if a phone/tablet has a valid SIM and is on a network it may be barred from making phone calls by the operator or by the user (call barring/call restriction); or it may not be able to call your particular number (no service, or international call out restricted, etc.) there would be no way for you to know unless you attempt a call _to the number_ that you are trying to reach. – Burhan Khalid Jul 12 '12 at 08:26
  • Never tried it, but I read about http://www.handsetdetection.com/ recently – danneth Jul 12 '12 at 08:37
  • I wouldn't worry about restrictions or barring because our target users are on personal devices, which would honestly be weird to restrict yourself. – Jerry Tseng-shen Hsu Jul 12 '12 at 08:43
  • handsetdetection.com I've actually seen before, but it's a paid service which I would rather find a way to not have to pay.....I'm cheap, I rather edit all user agents on my database than use their service... – Jerry Tseng-shen Hsu Jul 12 '12 at 08:50
  • As for having both, I thought of that, and we're trying to avoid having to do that. – Jerry Tseng-shen Hsu Jul 12 '12 at 08:51

1 Answers1

1

Here is a PHP class I use which detects mobile browsers that you can download fro free. http://code.google.com/p/php-mobile-detect/

Once the class in set up correctly you can use code like this:

if ($detect->isMobile()) {
    // any mobile platform
    // place telephone code here
}

or you can be more specific:

if($detect->isiOS()){
    // code to run for the Apple iOS platform.
}

This is generally used for creating mobile websites however it will fit your purpose :)

Peter Stuart
  • 2,362
  • 7
  • 42
  • 73
  • this solution actually does the trick by using the patterns in the useragent instead of having a database....plus you could change it and make a new category. Seems like a useful plugin, but makes me realize that many devices may have a phone number, but wasn't intended to make a phone call... – Jerry Tseng-shen Hsu Jul 13 '12 at 00:15
  • Very true, mobile technology is brilliant and its only going to keep getting better. Im glad this worked for you, it saves a lot of time and work building it yourself! I use this for mobile optimized websites – Peter Stuart Jul 13 '12 at 00:23