3

I am building an android application. I am showing external webpage in webview. I have followed these steps:

  1. Load external website in webview. For example example.com, it loads fine in webview
  2. There is an option in example.com site to launch Dialer app on button click. Here is the code.

    <div class="center">
        <input type="image" src="btn.png" onclick="location.href='tel:0000';"/>
    </div>
    
  3. When I go to example.com from mobile browser and click on button, it can launch Dialer app with phone number

  4. When I click from webview it shows this error

    Web page not available
    The web page at tel:0000 could not be loaded because:
    net::ERR_UNKNOWN_URL_SCHEME
    

I do not know what is went wrong. Any clue will be helpfull.

NB: I am using real phone number (here it is 0000).

Thank you

Nadim Iqbal
  • 103
  • 2
  • 14

1 Answers1

5

You should set a WebViewClient to the WebView and than override shouldOverrideUrlLoading method as follow:

myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            if (request.getUrl().toString().startsWith("tel:")) {
                Intent intent = new Intent(Intent.ACTION_DIAL, request.getUrl());
                view.getContext().startActivity(intent);
            }
            return super.shouldOverrideUrlLoading(view, request);
        }
    });
dariocast
  • 81
  • 4