Question

I have an app which gives normal landline numbers for UK 08 numbers.

Currently this is a web page shown in the app, when the user finds the number they want and click on the green phone icon. I'm using the following JavaScript to force then force a tel: link with the number to bring up the dailer.

document.location.href = 'tel:'+number;//push browser to call number

This method works fine for all newer android 4.0 and above as far as i can see. But when i use my old Orange San Francisco Phone (android 2.3) it doesnt bring the dailer. Instead it just attempts to open a new page with tel:01xxxxxxxx as the URL which in turn displays a web page not available message.

I assume this is because tel: is part of HTML5 which is why it's not working. Is there any alternative that would work on all versions?

Was it helpful?

Solution

tel: is preferred - since the 1990's. callto: may work better for some devices. See also: How to mark-up phone numbers?

EDIT

Since you have the page running inside an Android WebView, you can handle this error with the hack (also described at Android WebView "tel:" links show web page not found):

myWebView.setWebViewClient(new WebViewClient() {  
    @Override  
    public boolean shouldOverrideUrlLoading(WebView view, String url) {  
        if (url.startsWith("tel:")) { 
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); 
            startActivity(intent); 
        }
        else if(url.startsWith("http:") || url.startsWith("https:")) {
            view.loadUrl(url);
        }
        return true;  
    }  
} 

For which you may need the permission

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top