6

I have a webview that I am creating. It seems to automatically be linkifying numbers into tel: urls. I didn't see a way to remove this ability (at least nothing similar to the way to enable it on a textview).

The code is pretty simple:

// populate the web view
WebView webView = (WebView) findViewById(R.id.app_info_webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

webView.setBackgroundColor(0);
String url = APP_INFO_BODY_HTML + "?versionName=" + versionName;

webView.loadUrl(url);

I have a copyright notice at the bottom of the page, android is changing the 2011 into a clickable link that opens the dialer. Also, the App version 1.0.0 opens in the dialer.

Is there a way to disable this functionality?

Update: I just discovered that this seems device dependent...happens on the Droid X, but not a Samsung Captivate, not on Nexus S, and not the emulator.

Innova
  • 1,751
  • 2
  • 18
  • 26
  • you mentioned that using a textview would be fine too. here you find a link on how to add links to a textview http://android-developers.blogspot.com/2008/03/linkify-your-text.html – Fender Mar 29 '11 at 12:37

3 Answers3

7

There is a way to do that - rather ugly, two layered, but still a workaround.

You should

  1. modify how the webview will handle the auto-linkifiable items
  2. explicitly tell the loaded page not to apply styles and haptic feedback.

    mWebView.setWebViewClient( new WebViewClient() {
    
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, final String url) {
        Uri uri = Uri.parse(url);
    
        //TODO analyse the uri here 
        //and exclude phone and email from triggering any action
    
        return false;
    }
    
    public void onReceivedError(WebView view, int errorCode, 
                                            String description, String failingUrl) {}
    
    public void onPageFinished (WebView view, String url) {...}
    
    public void onPageStarted(WebView view, String url, Bitmap favicon) {...}
    
    public void onLoadResource(WebView view, String url) {...}
    }); 
    

    In the html specify the following meta tags inside the tag:

    <meta name="format-detection" content="telephone=no" />
    <meta name="format-detection" content="email=no" />
    

Hope this helps.

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
N.G.
  • 71
  • 1
  • 2
  • 2
    I think there is a third format-detection type: . Telephone-no stops automatic tel: links, email stops automatic mailto: links, and address stops geo: links. I can't find any official documentation on email or address. http://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariHTMLRef/Articles/MetaTags.html only mentions telephone. – Michael Levy Mar 22 '12 at 19:50
0

I'm surprised to see it is launching Dialer on selecting a number from your own WebView.

Unless, you override WebViewClient::shouldOverrideUrlLoading() and detect the url scheme has "tel" and start Dialer activity, it will never launch a Dialer from your WebView. Are you sure you are not handling tel: scheme in shouldOverrideUrlLoading()?

Sukumar
  • 1,303
  • 10
  • 15
-2

You can find the code that do the real detection in external/webkit/WebKit/android/nav/CacheBuilder.cpp : FindPartialNumber() and so on.

You can disable it or change the logic as you like.

SchmitzIT
  • 9,227
  • 9
  • 65
  • 92