Disable the automatic Linkify of Webview

后端 未结 3 623
南方客
南方客 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:

      
      
      

    Hope this helps.

提交回复
热议问题