从 Android 中的 HTML 页面拨打电话号码时获取 net::ERR_UNKNOWN_URL_SCHEME [英] Getting net::ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android

查看:23
本文介绍了从 Android 中的 HTML 页面拨打电话号码时获取 net::ERR_UNKNOWN_URL_SCHEME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 Android 的 HTML 页面调用电话号码选项时收到net::ERR_UNKNOWN_URL_SCHEME".我是否需要在清单中添加任何权限才能使其正常工作?到目前为止,我还没有在清单中添加任何内容.这是 HTML 代码:

I am getting "net::ERR_UNKNOWN_URL_SCHEME" while calling a telephone number option from an HTML page in Android. Do I need to add any permission(s) in the manifest to get this working? I haven't added anything in the manifest so far. Here's the HTML Code:

免费致电我们!</a>

推荐答案

以下应该可以工作并且不需要清单中的任何权限(基本上覆盖 shouldOverrideUrlLoading 并单独处理与 tel、mailto 等的链接):

The following should work and not require any permissions in the manifest (basically override shouldOverrideUrlLoading and handle links separately from tel, mailto, etc.):

    mWebView = (WebView) findViewById(R.id.web_view);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    mWebView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if( url.startsWith("http:") || url.startsWith("https:") ) {
                return false;
            }

            // Otherwise allow the OS to handle things like tel, mailto, etc.
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity( intent );
            return true;
        }
    });
    mWebView.loadUrl(url);

另外,请注意,在上面的代码片段中,我启用了 JavaScript,您也很可能需要它,但如果由于某种原因您不这样做,只需删除这两行即可.

Also, note that in the above snippet I am enabling JavaScript, which you will also most likely want, but if for some reason you don't, just remove those 2 lines.

这篇关于从 Android 中的 HTML 页面拨打电话号码时获取 net::ERR_UNKNOWN_URL_SCHEME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆