ERR_UNKNOWN_URL_SCHEME Chrome webview client android html file href="tel:"

1

I need the necessary code to write to my MainActivity.java, to avoid the error ERR_UNKNOWN_URL_SCHEME , I am creating an android application with Chrome webview client that loads an .html file that contains buttons href="tel:" mailto: etc ... but I do not want to use phonegap nor cordova nor any plugin, if someone knows how to solve it please indicate your answer, I have a bit of code that does not solve anything, but maybe it helps, I'll attach it below.

that's how I have the html and javascript

this.myBrowser.loadUrl("file:///android_asset/index.html");

// Link Treatment Starts

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub



                if(url != null && url.startsWith("whatsapp://"))
                {
                    view.getContext().startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(url)));
                    return true;

                }else
                {
                    return false;
                }



            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // Use an external email program if the link begins with "mailto:".
                if (url.startsWith("mailto:")) {
                    // We use 'ACTION_SENDTO' instead of 'ACTION_SEND' so that only email programs are launched.
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);

                    // Parse the url and set it as the data for the 'Intent'.
                    emailIntent.setData(Uri.parse(url));

                    // 'FLAG_ACTIVITY_NEW_TASK' opens the email program in a new task instead as part of this application.
                    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    // Make it so.
                    startActivity(emailIntent);
                    return true;
                } else {  // Load the URL in 'webView'.
                    webView.loadUrl(url);
                    return true;
                }
            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if(url.startsWith("mailto:")){
                    MailTo mt = MailTo.parse(url);
                    Intent i = new Intent(Intent.ACTION_SEND);
                    i.setType("text/plain");
                    i.putExtra(Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
                    i.putExtra(Intent.EXTRA_SUBJECT, mt.getSubject());
                    i.putExtra(Intent.EXTRA_CC, mt.getCc());
                    i.putExtra(Intent.EXTRA_TEXT, mt.getBody());
                    Context.startActivity(i);
                    view.reload();
                    return true;
                }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if(url.startsWith("tel:")){
                    Intent intent = null;
                    try {
                        intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                    view.getContext().startActivity(intent);
                }else {
                    return false;
                }
                view.reload();
                return true;
            }

            public boolean shouldOverrideUrlLoadingg(WebView view, String url) {
                if (url.startsWith("mailto:") || url.startsWith("tel:") || url.startsWith("geopoint:")) {
                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse(url));
                    startActivity(intent);
                }
                view.loadUrl(url);
                return true;
            }

            public boolean shouldOverrideUrlLoading1(WebView view, String url) {
                if (url.startsWith("tel:")) {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    startActivity(intent);
                    view.reload();
                    return true;
                }

                view.loadUrl(url);
                return true;
            }

            public boolean shouldOverrideUrlLoading2(WebView webview, String url)
            {
                if (url.startsWith("tel:") || url.startsWith("sms:") || url.startsWith("smsto:") || url.startsWith("mms://") || url.startsWith("mmsto:"))
                {
                    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
                return false;
            }

            public boolean shouldOverrideUrlLoading3(WebView view, String url) {
                if( url.startsWith("http:") || url.startsWith("https:") ) {
                    return false;
                }

                // Otherwise allow the OS to handle it
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(url));
                startActivity(intent);
                return true;
            }

            public boolean shouldOverrideUrlLoading4(WebView view, String url) {
                if( url.startsWith("http:") || url.startsWith("https:") ) {
                    return false;
                }

                // Otherwise allow the OS to handle it
                else if (url.startsWith("tel:")) {
                    Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    startActivity(tel);
                    return true;
                }
                else if (url.startsWith("mailto:")) {
                    String body = "Enter your Question, Enquiry or Feedback below:\n\n";
                    Intent mail = new Intent(Intent.ACTION_SEND);
                    mail.setType("application/octet-stream");
                    mail.putExtra(Intent.EXTRA_EMAIL, new String[]{"email address"});
                    mail.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                    mail.putExtra(Intent.EXTRA_TEXT, body);
                    startActivity(mail);
                    return true;
                }
                return true;
            }

            public boolean shouldOverrideUrlLoading5(WebView view, String url) {
                if (url.startsWith("tel:")) {
                    Intent intent = new Intent(Intent.ACTION_DIAL,
                            Uri.parse(url));
                    startActivity(intent);
                }else if(url.startsWith("http:") || url.startsWith("https:")) {
                    view.loadUrl(url);
                }
                return true;
            }





            public boolean shouldOverrideUrlLoading6(WebView wv, String url) {
                if(url.startsWith("callto:")||url.startsWith("tel:")||url.startsWith("sms:")) {
                    Intent intent = new Intent(Intent.ACTION_DIAL);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
                return false;
            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith("tel:")) {
                    Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    startActivity(tel);
                    return true;
                }
                else if (url.contains("mailto:")) {
                    view.getContext().startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                    return true;

                }else {
                    view.loadUrl(url);
                    return true;
                }
            }















            @SuppressWarnings("deprecation")

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url.startsWith("mailto:")) {
                    //Handle mail Urls
                    startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse(url)));
                } else if (url.startsWith("tel:")) {
                    //Handle telephony Urls
                    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(url)));
                } else {
                    view.loadUrl(url);
                }
                return true;
            }

            @TargetApi(Build.VERSION_CODES.N)

            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                final Uri uri = request.getUrl();
                if (uri.toString().startsWith("mailto:")) {
                    //Handle mail Urls
                    startActivity(new Intent(Intent.ACTION_SENDTO, uri));
                } else if (uri.toString().startsWith("tel:")) {
                    //Handle telephony Urls
                    startActivity(new Intent(Intent.ACTION_DIAL, uri));
                } else {
                    //Handle Web Urls
                    view.loadUrl(uri.toString());
                }
                return true;
            }


//Tratamiento de enlaces acaba
    
asked by MBS.corp 02.11.2017 в 17:50
source

1 answer

-1

The error you mention in your question refers to the fact that you do not recognize the protocol you indicate for a certain action, in this case tel: through the intent defined as Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); :

  

ERR_UNKNOWN_URL_SCHEME Chrome webview client android html file   href="tel:"

To support the tel: scheme without any problem, I suggest using Intent.ACTION_VIEW (instead of Intent.ACTION_DIAL), for both "tel:" and "mailto:":

 public boolean shouldOverrideUrlLoading(WebView view, String url) {
                /*if (url.startsWith("tel:")) {
                    Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
                    startActivity(tel);
                    return true;
                }*/
                if( url.startsWith("tel:") || url.startsWith("mailto:") ) {
                      view.getContext().startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                    return true;
               /*}else if (url.contains("mailto:")) {
                    view.getContext().startActivity(
                            new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                    return true;    */
                }else {
                    view.loadUrl(url);
                    return true;
                }
            }

In addition to the above, the scheme defined in your html for a phone number is incorrect

 tel://+34 555666777

It should be only:

tel:+34 555666777
    
answered by 02.11.2017 / 18:35
source