X

Ways to fix the ‘err_unknown_url_scheme’ Android WebView Error

What’s the err_unknown_url_scheme Android WebView error?

The err_unknown_url_scheme error normally comes up throughout Android WebView app improvement when a developer has chosen links to have mailto://, whatsapp://, or some other intent that’s not the fundamental http:// or https://. Particular URL coding must be added to deal with these distinction URL schemes to forestall this error. The dialogue and options for this text are directed in direction of Android builders. In case you are a consumer and run into this error, there’s nothing you are able to do to right away clear up the issue. Your greatest plan of action can be to contact the app developer to verify they’re conscious of this bug.
err_unknown_url_scheme android webview

Android Dominance

Android is the dominant working system (OS) for cellular gadgets. Android boasts a 71% market share, adopted by Apple’s iOS with 27% market share. Google purchased Android Inc. in 2005 in an effort to have management over Android’s future improvement and to load Android OS on all of its cellular gadgets. All different main cellular gadget producers, apart from Apple, use Android. Samsung, OnePlus, Huawei, Motorola, Nokia, LG, and Sony gadgets all come preloaded with the Android OS. It’s additionally considerably simpler to develop and host an app on Google’s Play Retailer than on Apple’s App Retailer. These elements have contributed to a strong Android developer group. Android builders use meetups and conferences, slack and Reddit, blogs and boards, and Stack Overflow to speak and study from one another. Many builders are self-taught and depend on the insights of the Android group to beat persistent programming errors and bugs. Android Studio is the one official improvement setting for Android. Android Studio was constructed utilizing JetBrains’ software program, the identical firm accountable for a wide range of different standard IDEs (built-in improvement environments) for languages like Python (Pycharm), PHP (PhpStorm), and Java (IntelliJ IDEA). Also read: How To Fix SIM Not Provisioned MM#2 Error

What are Native Apps? How are they associated to the err_unknown_url_scheme error?

Native apps stay within the Google Play Retailer or App Retailer. They’re totally developed functions which might be put in instantly onto the cellular gadget. Native apps will preserve most of their performance even when not related to the web or cellular networks. These differ from internet apps, that are merely web sites. Net functions are simpler to develop however don’t have entry to any system options like GPS. As a developer chances are you’ll wish to construct a local app however nonetheless present entry to internet content material. That is performed utilizing WebView. WebView is a particular class that permits internet content material to be displayed inside your native app. For instance, in case you have the native Fb app in your cellphone and click on an exterior hyperlink, the webpage will load throughout the app. You possibly can navigate round on the loaded webpage, entry different elements of the webpage, store, and work together. The embedded browser is not going to have an tackle bar on your consumer to go looking with. This supplies the developer a option to have each the advantages of an online app and a local app. WebView is ready to deal with sure URL schemes. In the event you attempt to use a particular URL scheme outdoors the usual https:// and http://, WebView can throw the err_unknown_url_scheme error. A couple of of the non-standard URL schemes that WebView isn’t set to acknowledge are:
  • mailto://
  • whatsup://
  • file://
  • telnet://
  • intent://
  • market://
  • app://

3 methods to repair the err_unknown_url_scheme error

To unravel this error, you possibly can go one in every of two routes: both disable these schemes and solely develop your app utilizing http:// and https:// schemes, or you possibly can edit your code to have the ability to deal with these particular URL schemes. The primary choice shouldn’t be an absolute resolution however can repair the issue in some use circumstances. The second resolution reveals examples of how one can add new intents for URL schemes, and the third resolution includes disabling any non-standard URL schemes.

1. Open In New Window

A fast and straightforward stopgap resolution is modifying your URL href code. By including target=”_blank” you’ll be able to clear up the issue in a roundabout means. Now including this snippet of code can have an undesirable improvement impact as a result of this hyperlink will now open in a brand new window. Improvement greatest observe is to keep away from opening further browser home windows. It’s because a brand new browser can trouble or confuse your consumer. By eradicating the ‘again’ button, customers discover it harder to navigate and get again to their earlier web page in your app. The usual is target=”_self”, which opens the hyperlink in the identical browser web page. Beneath is an instance of URL href code with goal=”_blank” added in:
<a href= “tel:555-111-5555” target=”_blank”> Contact Me </a>
Or:
<a href=”mailto:myname@gmail.com” target=”_blank”> Email Me </a>

2. Add New Intent to Load in Exterior App

In Android improvement, intents are used to inform Android what you need the app to do, primarily permitting you to name a particular motion or element. Some scheme errors could be mounted by including an intent to load in an exterior app. For instance, loading mailto:// in an exterior app ought to trigger the email hyperlink to open in your default email software. One other instance is maps:// which ought to open in your default maps software. Within the code snippet under, you can be utilizing an IF assertion to deal with this. Any URL that begins with http:// or https:// is ignored and opened as standard. In any other case, if the URL includes a particular scheme akin to:
  • tel://
  • sms://
  • mailto://
  • geo://
  • maps://
then a brand new intent is added to load the motion in an exterior app. If the exercise can’t be efficiently began as a result of no related exterior app exists on that system, an error will seem to the consumer.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url == null || url.startsWith("http://") || url.startsWith("https://")) {
        return false;
    } 

    attempt {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    } catch (Exception e) {
        Log.i(TAG, "shouldOverrideUrlLoading Exception:" + e);
        return true;
    }
}
One other code snippet is included under to indicate that you would be able to deal with this drawback in a wide range of methods. This methodology overrides URL loading like seen above and will open a associated app to hold out the protocol. If the related software, on this case Whatsapp shouldn’t be put in, a message is displayed on your consumer. This message known as a toast message and offers the consumer an thought on what went improper and how one can repair it. The toast message for this scheme was ‘Whatsapp has not been put in’.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);

    if (url.startsWith("whatsapp://")) {
        webview.stopLoading();
        try  catch (android.content.ActivityNotFoundException ex) 

            String MakeShortText = "Whatsapp has not been installed";

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

3. Disable any non-standard URL schemes

By disabling URL schemes aside from the usual https:// and http:// you’re bypassing this drawback utterly. You received’t have the ability to use any customized schemes like those listed earlier within the article. In case your app has one in every of these schemes or a consumer by some means navigates to a hyperlink utilizing these schemes, a toast message will seem. The message “Error: Unknown link type” will inform the consumer they will’t proceed. Beneath is an instance of this methodology:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (url.startsWith("http") || url.startsWith("https")) {
    return true;
}else 
return false;
}

WebView Has Nice Advantages, However Some Inventive Coding Is Wanted

Android WebView actually supplies one of the best of each worlds for Android builders, however inventive workarounds are wanted for some conditions. Through the use of WebView to show an embedded browser inside your native app, you achieve all the advantages of each the native app and an online app. It is possible for you to to make use of the native system APIs in your internet code which is normally constrained. In case you are growing an app and wish to embrace particular URLs, outside of http:// and https:// you will want so as to add some intents or fall again URLs, in any other case your our customers will expertise the error “err_unknown_url_scheme”. When a URL like mailto:// or maps:// known as, your code must open an related exterior app that may full that motion. In any other case you possibly can disable these different URLs and set a specific error message to any customers that stumbles upon a hyperlink with one in every of these URL schemes.
Categories: Tech
Jessica Fletcher:
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings