Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing autolinking of emails and URLs in an Android WebView

I have a WebView which may contain data that appears to be getting "auto linked". Something that looks like an email address is becoming clickable, even though it's now within an <a> tag or has an onclick attribute. How do I disable this auto-linking?

I've looked thorugh the WebView docs, as well as the WebSettings docs, but didn't seem to see anything that mentions this behavior.

alt text http://beautifulpixel.com/assets/5554_Fast-20100706-110228.png

like image 930
Alex Wayne Avatar asked Jul 06 '10 17:07

Alex Wayne


1 Answers

I know this is a bit late, but for future reference, this might be a solution that will work regardless if the links are auto created or defined in the <a>-tag.

myWebView.setWebViewClient(new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // return true; // will disable all links

        // disable phone and email links
        if(url.startsWith("mailto") || url.startsWith("tel")) {
            return true;
        }

        // leave the decision to the webview
        return false;
    }
});
like image 80
Paaske Avatar answered Nov 11 '22 06:11

Paaske