Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Webview ERR_UNKNOWN_URL_SCHEME Error

Tags:

android

mailto

When I click a link which goes to mailto:[email protected] I get this error:

net: ERR_UNKNOWN_URL_SCHEME

I tried to add an if(url.startsWith("mailto:")) condition but it's not working.

This is my MyWebViewClient method:

public class MyWebViewClient extends WebViewClient {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {

        }

        @Override
        public void onPageFinished(WebView view, String url) {
            view.setVisibility(View.VISIBLE);
            final Animation fade = new AlphaAnimation(0.0f, 1.0f);
            fade.setDuration(200);
            view.startAnimation(fade);
            view.setVisibility(View.VISIBLE);

        }

    }
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(url.startsWith("mailto:")){
            Intent intent = null;
            try {
                intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            view.getContext().startActivity(intent);
        }
        else if (url.endsWith(".mp3")) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), "audio/*");
            startActivity(intent);

        } else if (url.endsWith(".mp4") || url.endsWith(".3gp")) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), "video/*");
            startActivity(intent);
        }
        else {
            return false;
        }
        view.reload();
        return true;
    }

and this is how I add the function to my web view before loadUrl:

...
mWebview.setWebViewClient(new MyWebViewClient());
...
like image 628
Dauezevy Avatar asked Apr 24 '15 16:04

Dauezevy


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?

There are a few ways to solve this issue. One option is to install an app called UrlFixer, which will automatically convert unrecognized URL schemes into ones that your device can understand. Another option is to enable developer options on your device and then set the "Override software navigation" setting to "On".

What does this error mean net :: Err_cleartext_not_permitted?

Following the Android 9 update, all applications using Android Webview should use HTTPS; otherwise, the system will throw the net::err_cleartext_not_permitted error. In short, this error will appear to users of your application because of Android's network security configuration when accessing HTTP URLs.


1 Answers

try this

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());
        mContext.startActivity(i);
        view.reload();
        return true;
    } 
like image 148
Amit K. Saha Avatar answered Oct 10 '22 12:10

Amit K. Saha