Disable the automatic Linkify of Webview

五迷三道 提交于 2019-11-29 10:42:32
N.G.

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.

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

shaowei_zhang

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!