我正在构建一个 android 应用程序。我在 webview 中显示外部网页。我已按照以下步骤操作:
- 在 WebView 中加载外部网站。例如 example.com,它在 webview 中加载正常
example.com 站点中有一个选项可以在单击按钮时启动拨号器应用程序。这是代码。
<div class="center"> <input type="image" src="btn.png" onclick="location.href='tel:0000';"/> </div>
当我从移动浏览器转到 example.com 并单击按钮时,它可以启动带有电话号码的拨号器应用
当我从 webview 中点击时,它显示了这个错误
Web page not available The web page at tel:0000 could not be loaded because: net::ERR_UNKNOWN_URL_SCHEME
我不知道哪里出了问题。任何线索都会有所帮助。
注意:我使用的是真实电话号码(这里是 0000)。
谢谢
最佳答案
您应该为 WebView 设置一个 WebViewClient,而不是重写 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);
}
});
关于Android webview 电话 :0000 could not be loaded because net:ERR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49274976/