What is the err_unknown_url_scheme Android WebView error?

The err_unknown_url_scheme error normally comes up during Android WebView app breakthrough when a developer has chosen web links to have mailto://, whatsapp://, or any kind of other intent that’s not the basic http:// or https://. Particular URL coding requirements to be added to handle these difference URL schemes to prevent this error.

You are watching: Net::err_unknown_url_scheme

*

What are native Apps? how are they regarded the err_unknown_url_scheme error?

Native apps live in the Google Play save or application Store. Lock are totally developed applications that are installed directly onto the mobile device. Aboriginal apps will preserve most of your functionality even when not linked to the web or cell phone networks. These differ from web apps, i beg your pardon are simply websites. Net applications are much easier to construct but nothing have access to any type of system features like GPS.

As a developer you may want to build a native application but quiet provide accessibility to web content. This is done making use of WebView. WebView is a special class that allows web contents to be displayed within your native app. For example, if you have actually the aboriginal Facebook application on your phone and also click an external link, the webpage will pack within the app. You can navigate about on the loaded webpage, access other components of the webpage, shop, and interact. The embedded web browser will not have actually an resolve bar for your user to find with. This gives the developer a method to have actually both the benefits of a internet app and a native app.

WebView is collection to handle specific URL schemes. If you try to usage a one-of-a-kind URL scheme exterior the conventional https:// and http://, WebView have the right to throw the err_unknown_url_scheme error. A few of the non-standard URL schemes that WebView isn’t set to identify are:

mailto://whatsup://file://telnet://intent://market://app://
*

3 ways to settle the err_unknown_url_scheme error

To deal with this error, you have the right to go among two routes: one of two people disable those schemes and also only build your app using http:// and https:// schemes, or you can modify your password to be able to handle these details URL schemes. The very first option is no an absolute solution yet can solve the difficulty in some usage cases. The second solution shows examples of exactly how to add new intents because that URL schemes, and the third solution entails disabling any non-standard URL schemes.

1. Open In brand-new Window

A quick and easy stopgap equipment is modifying your URL href code. By adding target=”_blank” you space able to solve the problem in a roundabout way. Now including this snippet that code can have one undesirable advancement effect because this connect will now open in a new window.

Development ideal practice is to avoid opening extra internet browser windows. This is due to the fact that a new browser have the right to bother or confuse her user. By remove the ‘back’ button, users find it more an overwhelming to navigate and get earlier to their previous page in her app. The traditional is target=”_self”, which opens up the connect in the same browser page.

Below is an instance of URL href code through target=”_blank” added in:

contact Me Or:

email Me

2. Add new Intent to pack in exterior App

In Android development, intents are provided to call Android what you want the app to do, essentially enabling you to speak to a particular action or component. Some system errors can be resolved by including an will to fill in an external app. Because that example, loading mailto:// in one external application should cause the email link to open up in her default email application. An additional example is maps:// which must open in her default maps application.

In the code snippet below, you will certainly be using an IF explain to take care of this. Any kind of URL that starts with http:// or https:// is ignored and opened as usual. Otherwise, if the URL entails a special scheme such as:

tel://sms://mailto://geo://maps://

then a new intent is added to load the activity in an outside app. If the task cannot be successfully started due to the fact that no linked external application exists on the system, an error will show up to the user.


Overridepublic boolean shouldOverrideUrlLoading(WebView view, wire url) Another password snippet is included below to display that you can tackle this difficulty in a range of ways. This technique overrides URL loading like seen above and should open a related application to carry out the protocol. If the associated application, in this situation Whatsapp is no installed, a message is shown for her user. This post is referred to as a toast message and gives the user an idea ~ above what go wrong and how to fix it. The toast article for this scheme was ‘Whatsapp has not to be installed’.


Overridepublic boolean shouldOverrideUrlLoading(WebView view, string url) view.loadUrl(url); if (url.startsWith("whatsapp://")) webview.stopLoading(); shot intent whatsappIntent = brand-new Intent(Intent.ACTION_SEND); whatsappIntent.setType("text/plain"); whatsappIntent.setPackage("com.whatsapp"); whatsappIntent.putExtra(Intent.EXTRA_TEXT, webview.getUrl() + " - mutual from webview "); startActivity(whatsappIntent); capture (android.content.ActivityNotFoundException ex) wire MakeShortText = "Whatsapp has actually not been installed"; Toast.makeText(WebactivityTab1.this, MakeShortText, Toast.LENGTH_SHORT).show(); ;;

3. Disable any type of non-standard URL schemes

By disabling URL schemes other than the standard https:// and also http:// you room bypassing this trouble completely. You won’t have the ability to use any custom schemes choose the ones noted earlier in the article.

If your app has among these schemes or a user in which method navigates come a connect using this schemes, a toast post will appear. The article “Error: Unknown attach type” will certainly tell the user they can not proceed. Listed below is an instance of this method:


Overridepublic boolean shouldOverrideUrlLoading(WebView view, wire url) url.startsWith("https")) return true;else webview.stopLoading(); webview.goBack(); Toast.makeText(MainActivity.this, "Error: Unknown attach type", Toast.LENGTH_SHORT).show();return false;

WebView Has an excellent Benefits, yet Some an innovative Coding Is Needed

Android WebView really offers the best of both people for Android developers, but creative workarounds are required for some situations. By utilizing WebView to display an embedded internet browser within your native app, you acquire all the benefits of both the indigenous app and a net app. Friend will have the ability to use the native system APIs in your web code i m sorry is typically constrained.

If you are occurring an app and also want to include special URLs, exterior of http:// and https:// you will need to include some intents or fall back URLs, otherwise your our individuals will suffer the error “err_unknown_url_scheme”. Once a URL prefer mailto:// or maps:// is called, your code requirements to open an connected external application that can complete that action. Otherwise you have the right to disable these various other URLs and collection a specific error message to any type of users the stumbles upon a link with one of these URL schemes.

See more: How To Unlock Samsung Galaxy S6 Active By Code, Unlock Samsung Galaxy S6 Active


Leave a Comment release reply

Comment

NameEmail

save my name, email, and website in this internet browser for the following time i comment.