简体   繁体   中英

Android WebView “tel:” & “mailto:”links show web page not found

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;
} 

}

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; 
  }

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

This should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM