繁体   English   中英

Android webview tel:0000 无法加载,因为 net:ERR

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

我正在构建一个 android 应用程序。 我在 webview 中显示外部网页。 我已按照以下步骤操作:

  1. 在 webview 中加载外部网站。 例如 example.com,它在 webview 中加载正常
  2. example.com 站点中有一个选项可以在单击按钮时启动拨号器应用程序。 这是代码。

     <div class="center"> <input type="image" src="btn.png" onclick="location.href='tel:0000';"/> </div>
  3. 当我从移动浏览器转到 example.com 并单击按钮时,它可以启动带有电话号码的拨号器应用程序

  4. 当我从 webview 单击时,它显示此错误

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

我不知道出了什么问题。 任何线索都会有所帮助。

注意:我使用的是真实电话号码(这里是 0000)。

谢谢

您应该将 WebViewClient 设置为 WebView,而不是重写 shouldOverrideUrlLoading 方法,如下所示:

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);
        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM