How to Fix Unknown URL Scheme in Android WebView

The unknown url error screen

Fix err_unknown_url_scheme intent://,whatsapp:// etc in Android WebView

Updated on 12 – October,2020.

This error is appeared in your android webview app because the WebView can’t recognize the special URL Schemes

For example, the WebView will usually recognize http and https, anything other than these, for example – intent://, market://, tel://, mailto:// , whatsapp:// etc will not be recognized by WebView unless we add a handler code to handle these url schemes, or by disabling these schemes and only load http and https schemes.




 

What are URL schemes in android?

The url schemes like intent://, market://, app://, mailto:// etc are special URL schemes in the webview that can be used to open apps from webview, invoke an android activity or do an action etc. For example, the mailto:// url scheme can be used to send email action directly from the webview.

You can even make your own url scheme and make the webview recognize it so the webview can do your own action that you define

Another example is market://, this can be used to open google playstore action from the webview, another example is whatsapp://, this can be used to directly share a text or link from webview to whatsapp messenger.

If we do not set actions whenever the special url schemes are invoked, it will show the unknown url scheme error. It is possible to stop showing the error screen with a few lines of code, but it is better to fix this error by adding additional code to handle the the url schemes. The additional code can be complex but we can help you.

We have built a webview app template after months of research, the app template now supports most url schemes, i suggest you try the template and you will not need look back and stress to fix the url schemes error, the template is easy to use

Save your time and stress, use our Advanced Webview Template

You can use our Advanced Webview Easy App Template that supports most url schemes and intents to open external apps such as Whatsapp, google playstore, email, tel etc. This template can be imported to android studio and you can change a few things to create a functional webview app and create apks, no more coding because most functions are built in already!

This template also supports the following things:

  • File upload
  • File download
  • Onesignal notifications
  • Drawer menu, bottom navigation bar, option menu
  • GPS access, dark theme and many other features.

This template will save your stress and time. Your full functional webview app for your website now can be easily built and ready in less than an hour using this app template.

All you need is set an app icon, set your website link, change some colors, change app and package name to turn the template to your desired android webview app that supports almost all webview functions.

If you want it, head to this page Download Android Webview Source Code Template.

How to Disable the Url Scheme Error Screen in Android

We can totally disable the error by writing a few lines of code in the onPageFinished and ShouldOverrideUrlLoading

but the problem here is that webview will not handle the schemes, so if you need open the mail app, the mail:// will not work, only https and http links will be handled by webview

Here is how to disable other url schemes and allow only http and https

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    String url = "http://www.google.com";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webactivity);


        final WebView webview = (WebView) findViewById(R.id.web1);
        webview.loadUrl(url);

        webview.setWebViewClient(new WebViewClient(){

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            if (url.startsWith("http") || url.startsWith("https")) {
                return true;
            }else {
                webview.stopLoading();
                webview.goBack();
                Toast.makeText(MainActivity.this, "Unknown Link, unable to handle", Toast.LENGTH_SHORT).show();
            }
            return false;



}});}}

 

How to set actions for these special url schemes

You can set actions to any of the url schemes with the onPageFinished  method in the webview

Here is an example

The code here is executed if the clicked url in the webview starts with whatsapp://,  if whatsapp is already installed, then the webview will attempt to share the current page link to whatsapp, if whatsapp is not installed, it will show a toast message

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);

                if (url.startsWith("whatsapp://")) {
                    webview.stopLoading();
                    try {
                        Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
                        whatsappIntent.setType("text/plain");
                        whatsappIntent.setPackage("com.whatsapp");

                        whatsappIntent.putExtra(Intent.EXTRA_TEXT, webview.getUrl() + "  - Shared from webview ");

                        startActivity(whatsappIntent);
                    } catch (android.content.ActivityNotFoundException ex) {

                        String MakeShortText = "Whatsapp have not been installed";

                        Toast.makeText(WebactivityTab1.this, MakeShortText, Toast.LENGTH_SHORT).show();
                    }


                }
                ;

            }});

Another examples

Here is an example to fix the common intent url scheme , we will learn how to handle the intent:// here , i noticed this error when i built an app that loads facebook messages, the error appeared whenever i tap on the message icon of facebook. i suppose this is because the facebook is sending you to app store to download the messenger app when you tap on the message icon. In the below code, we will fix it.

The Code to Fix err_unknown_url_scheme intent://

 

webview.setWebViewClient(new WebViewClient() {
           String currentUrl;

           @Override
           public boolean shouldOverrideUrlLoading(WebView view, String url) {
               currentUrl = url;

               if (url.startsWith("http") || url.startsWith("https")) {
                   return false;
               }
               if (url.startsWith("intent")) {




                 try {
                     Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);

                     String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                   if (fallbackUrl != null) {
                       webview.loadUrl(fallbackUrl);
                       return true;
                   }}

               catch (URISyntaxException e) {
                   //not an intent uri
               }
       return true;//do nothing in other cases

 

What we did in this code is whenever the url we clicked contain intent:// scheme, we try to override it and get the fallbackUrl to the string, then we try to load the url. this should fix the intent error




You can set your own scheme handler for your apps from these examples


Update: If you are new to android development, or just want fix this url scheme error code, i can fix it for you for a small fee of US $2 (₹150 indian rupees). Just send me your project or that java file (The MainActivity or the Activity where you wish to fix url scheme) through email or google drive, i will fix your project or file and send it back to you.

You can pay me through Paypal or any payment method your country supports. For more details, contact me through:

(Click to send email or whatsapp directly)


If you want convert your website to android app, we can do it, see this page Android advanced development
If you want see a list of other services we do, visit Services page

, , , ,

Post navigation

25 thoughts on “How to Fix Unknown URL Scheme in Android WebView

          1. where to add this code ?? I added in MainActivity but it is nor working.. and can i publish webview app in playstore? my website shows adsense ads, and i read somewhere adsense in webview app in not allow in playstore it is against admob policy ???

          2. You can add in main activity, yes, according to google’s rule, you are not allowed to show webview of a website you don’t own or don’t have permission. if you own the website, it is ok, but do not place admob ads in your app if your website has adsense. adsense+admob= ban or app disable

  1. To fi err unknow url scheme intent:// you can setup intent to startactivity in url like this

    try {
    if (url.startsWith(“intent”)) {
    Intent parseIntent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
    Intent lineIntent = new Intent(parseIntent.getAction());
    lineIntent.setData(parseIntent.getData());
    lineIntent.setPackage(parseIntent.getPackage());
    startActivity(lineIntent);
    } else {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(browserIntent);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }

    I made successfully with Line

  2. What can I do to enable Whatsapp and Telegram links on my webview app? I don’t know where to place the codes explained above. My MainAtctivity.java code is as below

    package com.bettingtipsterke;

    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.view.WindowManager;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    public class MainActivity extends AppCompatActivity {

    WebView wv ;
    // When Back Pressed Go Back.
    @Override
    public void onBackPressed() {
    if (wv.canGoBack()) {
    wv.goBack();
    } else {

    super.onBackPressed();
    }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    wv = (WebView) findViewById(R.id.wv);
    // Enable JavaScript
    wv.getSettings().setJavaScriptEnabled(true);
    // Set Render Priority To High
    wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    wv.getSettings().setDomStorageEnabled(true);
    wv.getSettings().setDatabaseEnabled(true);
    wv.getSettings().setAppCacheEnabled(true);
    wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    //Load Url
    wv.loadUrl(“https://mobile.bettingtipsterke.com”);
    wv.setWebViewClient(new WebViewClient());
    }
    }

  3. Hi there, How about paytm app? I manage to pull the paytm app, However, once you login into paytm app, The app doesn’t redirect to paytm app anymore

  4. error whatsapp and telegram my code is here

    package com.example.hp.fincoadvisors;

    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.webkit.URLUtil;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.widget.Toast;

    public class MainActivity extends ActionBarActivity {
    private WebView myWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myWebView = (WebView)findViewById(R.id.webView);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    myWebView.loadUrl(“https://www.fincoadvisors.com”);
    myWebView.setWebViewClient(new WebViewClient());
    }

    @Override
    public void onBackPressed() {
    if(myWebView.canGoBack())
    {
    myWebView.goBack();
    }
    else {
    super.onBackPressed();
    }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
    return true;
    }

    return super.onOptionsItemSelected(item);
    }
    }

    where should i include line for whatsapp and telegram

  5. Olá, boa tarde, estou com esse problema tbm, onde colocaria esse codigo para resolver?

    @Override
    público booleano shouldOverrideUrlLoading (exibição WebView, String url) {
    if (url == null || url.startsWith (“http: //”) || url.startsWith (“https: //”))
    return false;

    experimente {
    Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse (url));
    view.getContext (). startActivity (intent);
    return true;
    } catch (Exceção e) {
    /
    return true;
    }

    }

    obrigada

  6. i am getting an error in 1st code at @Override it say “method does not override or implement a method from a supertype”

      1. Yes you were right i did it successfully. Thank you
        Can you help me with playstore, like when i click on a link in webview it should redirect me to the playstore to particular app of link

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.