Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting net::ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android

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="tel:+1800229933">Call us free!</a>

like image 799
Karthik Avatar asked Jul 11 '14 12:07

Karthik


People also ask

How can I solve the error net Err_unknown_url_scheme in Android Webview?

You may get this "ERR_UNKNOWN_URL_SCHEME error" during mailto: or tel: links inside an iframe. To solve it, try to add target="_blank" in your URL Scheme/Code.

How do I fix Net :: Err_unknown_url_scheme?

– Solve Net err_unknown_url_scheme Error: Open in New Window It is an easy and quick solution that involves editing the URL href code. The error can be solved in a roundabout way by adding target=”_blank” and enabling an undesirable effect of development as a new window opens now by this link.


2 Answers

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

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.

like image 180
David M Avatar answered Sep 25 '22 02:09

David M


I had this issue occurring with mailto: and tel: links inside an iframe (in Chrome, not a webview). Clicking the links would show the grey "page not found" page and inspecting the page showed it had a ERR_UNKNOWN_URL_SCHEME error.

Adding target="_blank", as suggested by this discussion of the issue fixed the problem for me.

like image 28
Sly_cardinal Avatar answered Sep 22 '22 02:09

Sly_cardinal