4

I am trying to open tel: & mailto: link from webview, and receive the following message:

Web Page Not Found tel:0000000000

The only link that works is "http:" and "https"

Can anyone help me?

     private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView webview, String url)
    {
        webview.loadUrl(url);
        return true;
    }
}

@Override
public boolean onKeyDown(int KeyCode, KeyEvent event)
{
    if ((KeyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
    {
        mWebView.goBack();
        return true;
    }
    return super.onKeyDown(KeyCode, event);
}

public boolean shouldOverrideUrlLoading(WebView webview, String url) {
    if (url.startsWith("tel:")) { 
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url)); 
            startActivity(intent); 
    }else if(url.startsWith("http:") || url.startsWith("https:") || url.startsWith("mailto:")) {
        webview.loadUrl(url);
    }
    return false;
} 

}

robert
  • 61
  • 1
  • 5
  • Hey Robert, this may help you out:[Android WebView “tel:” links show web page not found](http://stackoverflow.com/questions/4338305/android-webview-tel-links-show-web-page-not-found) – Paresh Mayani Jun 17 '12 at 12:37

2 Answers2

2

Do not call loadUrl(url);

   public boolean shouldOverrideUrlLoading(WebView webView, String url) {

     if (url.startsWith("tel:")) {
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(url));
        activity.startActivity(intent);
    }
    else{
        webView.loadUrl(url);
    }
        return true; 
  }
0

Try to return false to the tel: and mailto: if and else if branches.

This should work.

Tim
  • 6,692
  • 2
  • 25
  • 30
  • @ Tim Messerschmidt i updated the code, only the "http" links are working, any suggestions? – robert Jul 13 '12 at 08:26
  • You handle the Intent for tel: wrong - it must look like this: Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); – Tim Jul 13 '12 at 11:06
  • @ Tim Messerschmidt Unfortunately even this solution does not work – robert Jul 13 '12 at 12:51
  • 1
    You must return true if you handle the intent and false if not. – Tim Jul 13 '12 at 13:10