Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - How to make a phone call from webview

In my app, i am opening the url using webview. This url opens the some page that contains some phone numbers.Now i want to make a phone call without open the phone dialer if u click on the phone number. is it possible? please can anybody help me.

thanks

like image 654
naresh Avatar asked Feb 23 '12 06:02

naresh


2 Answers

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;
    }
like image 184
Jayyrus Avatar answered Nov 20 '22 10:11

Jayyrus


Thanks JackTurky! Here's slightly more, to show how it fits with webView:

    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("tel:")) { 
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); 
                    startActivity(intent); 
                    return true;
            }
            return false;
        }           
    });
like image 45
CharlesW Avatar answered Nov 20 '22 11:11

CharlesW