Checking if android Device is able to make calls

You must Login before you can answer or comment on any questions.

I am developing an app for both iOS and Android. I have a Phone number that when clicked will prompt the user if they really want to dial the number. On iOS I do not want to dial the number or prompt the user if the device is not capable of making phone calls. On iOS I can test if the device should be able to make calls by using the Ti.Platform.canOpenURL('tel:5555555555') method. Android devices do not support that method. Is there a good way to check if an Android users device can make a phone call. In the case of a tablet that can not make a phone call, I don't want the user to receive the prompt. I have tried using the following code, which works on a device that is not able to make calls, but on an android device that is able to make calls the code dials the number without prompting the user first.

var telUrl = 'tel:5555555555';
 
if (Ti.Platform.osname !== 'android' {
    // iOS
    if (Ti.Platform.canOpenUrl(telUrl))
        alertDialog.show();
} else {
    // Android or other
    if (Ti.Platform.openUrl(telUrl))
        alertDialog.show();
}

3 Answers

Just create your own prompt using Ti.UI.AlertDialog

— answered 1 year ago by Shannon Hicks
answer permalink
2 Comments
  • I guess I should have clarified the code. That is what alertDialog.show() is. I just didn't write out the code to declare it in the example. But my question is not about the alertDialog. My question is: Is there a way to TEST if an android device has the ability to place calls.

    — commented 1 year ago by Frodeaux *

  • Sorry, I mis-understood what " I have tried using the following code, which works on a device that is not able to make calls, but on an android device that is able to make calls the code dials the number without prompting the user first." meant.

    — commented 1 year ago by Shannon Hicks

I don't think there's a good way to do this, even in native Android. I found this on StackOverflow which says you can try to use PackageManager.FEATURE_TELEPHONY (you'd have to write a native module for this with extended permissions) but Google Groups says that doesn't work on all phones. Other workarounds also seem to not work on all phones.

My instinct says that even though it's a great user experience, it's probably not worth the effort.

var telUrl = 'tel:5555555555';

if (Ti.Platform.osname !== 'android' { // iOS if (Ti.Platform.canOpenURL(telUrl)) alertDialog.show(); } else { // Android or other if (Ti.Platform.openURL(telUrl)) alertDialog.show(); }

Your Answer

Think you can help? Login to answer this question!