获得网:: ERR_UNKNOWN_URL_SCHEME而在Android的主叫电话号码从HTML页面而在、电话号码、页面、ERR_UNKNOWN_URL_SCHEME

2023-09-06 13:45:13 作者:镜子里的鬼魂

我收到网:: ERR_UNKNOWN_URL_SCHEME同时呼吁从Android的HTML页面中的电话号码选项。我是否需要添加任何权限(S)在清单中得到这个工作?我没有在清单迄今添加任何东西。这里的HTML code:

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 HREF =!电话:1800229933>联系我们免费< / A>

推荐答案

下面列出的工作,而不需要在清单中的任何权限(基本覆盖shouldOverrideUrlLoading和联系电话,邮寄地址等单独处理链接。):

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,您将很可能也想,但如果由于某种原因,你不这样做,只是删除那些2线。

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.