Android webview tel:0000 could not be loaded because net:ERR

五迷三道 提交于 2021-01-28 02:21:36

问题


I am building an android application. I am showing external webpage in webview. I have followed these steps:

  1. Load external website in webview. For example example.com, it loads fine in webview
  2. There is an option in example.com site to launch Dialer app on button click. Here is the code.

    <div class="center">
        <input type="image" src="btn.png" onclick="location.href='tel:0000';"/>
    </div>
    
  3. When I go to example.com from mobile browser and click on button, it can launch Dialer app with phone number

  4. When I click from webview it shows this error

    Web page not available
    The web page at tel:0000 could not be loaded because:
    net::ERR_UNKNOWN_URL_SCHEME
    

I do not know what is went wrong. Any clue will be helpfull.

NB: I am using real phone number (here it is 0000).

Thank you


回答1:


You should set a WebViewClient to the WebView and than override shouldOverrideUrlLoading method as follow:

myWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            if (request.getUrl().toString().startsWith("tel:")) {
                Intent intent = new Intent(Intent.ACTION_DIAL, request.getUrl());
                view.getContext().startActivity(intent);
            }
            return super.shouldOverrideUrlLoading(view, request);
        }
    });


来源:https://stackoverflow.com/questions/49274976/android-webview-tel0000-could-not-be-loaded-because-neterr

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