2

I am using webviewclient to open the html page. The html page is having a anchor tag. when i click on the anchor tag my phone dialer activity should be launched. when i click on this anchor tag in external browser (android default browser ), it is launching the phone dialer, but as i am using the webviewclient (browser with in my application). i am unable to launch the phone dialer.

is there any way to achieve this using webviewclient ?

RockandRoll
  • 409
  • 5
  • 23

2 Answers2

1

You should override this method

public boolean shouldOverrideUrlLoading(WebView wv, String url)
{
    if(isNumber)
    {
        //Get the number from the URL
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:12345"));
        startActivity(intent);
        return true;
    }
    return false;
}

in the WebViewClient, and return ture that means you want to handle this by yourself instead of the webView.

The document is here.

dreamtale
  • 2,905
  • 1
  • 26
  • 38
  • @dreamtale: what is isNumber here? And how to call above method? – YuDroid Dec 31 '12 at 11:35
  • @YuDroid isNumber is just a method to adjust whether the url has the phone number; The shouldOverrideUrlLoading method is an override method of the WebviewClient. more details you can visit the document of android(see the last of the above answer) – dreamtale Jan 03 '13 at 06:13
0

I think is the best way to do this. So Please try this, I know i am too late to reply this:

  webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if( URLUtil.isNetworkUrl(url) ) {
                view.loadUrl(url);
                return false;
            }

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity( intent );
            return true; /*
            return false;*/
        }
Sandeep Sankla
  • 1,250
  • 12
  • 21