androidandroid-webviewandroid-dialer

How to open Dialer Activity from a webviewclient with clicked number?


I am implementing a web view in my application. now when a user clicks on a phone number it shows net::ERR_UNKNOWN_URL_SCHEME. But if i use chrome. it brings the dialer application with that phonenumber.

I need the exact same thing in my application. When a phone number is clicked within webview then the dialer needs to be opened with that phone number.

Here is my shouldOverrideUrlLoading Method for the webview. I can see there is answer here. But i am pretty new to android and java and i couldn't make this thing work till now.

 public boolean shouldOverrideUrlLoading(WebView view, String url){
        progressBar.setVisibility(view.VISIBLE);
        view.loadUrl(url);
        return true;
   }

Solution

  • This must be working. we need to override the shouldOverrideUrlLoading method of the webview class. and check if the url contains the tel:xxxx Then create an intent for the dialer and invoke the dialer. and we can call any application we want like gmail app if its a mailto: link

    here is the methode.

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
       if(url.contains("tel:")) {
            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse(url));
            startActivity(intent);
            return true;
       } else {
            progressBar.setVisibility(view.VISIBLE);
            view.loadUrl(url);
            return true;
       }
    }