Disable the automatic Linkify of Webview

后端 未结 3 609
南方客
南方客 2020-12-19 09:21

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 t

相关标签:
3条回答
  • 2020-12-19 09:44

    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.

    0 讨论(0)
  • 2020-12-19 09:50

    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()?

    0 讨论(0)
  • 2020-12-19 10:00

    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.

    0 讨论(0)
提交回复
热议问题