Fix ERR_UNKNOWN_URL_SCHEME on Android WebView for tel:\sms:\geo:\etc links

I am building a hybrid mobile app with Visual Studio Tools for Apache Cordova that is able to make phone calls, send text message or emails, view a location on a map, etc. These are all handled with external applications (for instance use Gmail to send an email or Maps to pinpoint a location). They are placed in an anchor tag in HTML, such as <a href="tel:12345678">, <a href="sms:12345678">, <a href="mailto:name@domain.com"> or <a href="geo:...">. These work fine except that when you execute one of these actions and the system opens another app you see for a short time a webview with an error: “Web page not available”. Then the external app opens, you take the action and then go back to the app. At that point you again see this webview with the error as shown below.

ERR_UNKNOWN_URL_SCHEME when sending a text message
ERR_UNKNOWN_URL_SCHEME when sending a text message

This seem to be a known issue as I found many references of it on the web. Here are several for reference:

I am using the InAppBrowser plugin to open links in external apps. In order for this to work the schemes must be white-listed in Cordova’s config.xml file and the launch-external attribute should be set to true (which was already set in my case).

  
<access origin="mailto:*" launch-external="true" />
<access origin="tel:*" launch-external="true" />
<access origin="sms:*" launch-external="true" />
<access origin="geo:*" launch-external="true" />
<access origin="maps:*" launch-external="true" />

The indicated solution is to override WebView.shouldOverrideUrlLoading method.

I added the following in plugins\cordova-plugin-inappbrowser\src\android\InAppBrowser.java in the plugin’s WebView extension, but that did not work as the code did not even execute.

@Override
public boolean shouldOverrideUrlLoading(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);
   intent.setData(Uri.parse(url));
   cordova.getActivity().startActivity(intent);
   return true;
}

Looking for a solution I have noticed that this was only working OK for tel: and for others it was exhibiting this behavior. Then I found the following code in the InAppBrowser plugin class, in the execute() method.

//Load the dialer
else if (url.startsWith(WebView.SCHEME_TEL))
{
    try {
        Log.d(LOG_TAG, "loading in dialer");
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse(url));
        cordova.getActivity().startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
    }
}

I have changed that to include the other schemes and that fixed the problem.

else if (url.startsWith(WebView.SCHEME_TEL) || 
         url.startsWith("sms:") ||
         url.startsWith(WebView.SCHEME_MAILTO) ||
         url.startsWith(WebView.SCHEME_GEO) ||
         url.startsWith("maps:"))
{
    try {
        Log.d(LOG_TAG, "loading in external app");
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        cordova.getActivity().startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        LOG.e(LOG_TAG, "Error opening external app " + url + ": " + e.toString());
    }
}

With this in place, the web page error no longer shows up for any URL scheme.

I’m not sure if this is the best solution, but it is the only one that I managed to implement.

12 Replies to “Fix ERR_UNKNOWN_URL_SCHEME on Android WebView for tel:\sms:\geo:\etc links”

  1. Hello Sir,

    I have the same problem but in the store on ebay, our mail not works on android.
    Can i correct in the html the problem with a code ?

  2. public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if( url.startsWith(“http:”) || url.startsWith(“https:”) ) {
    return false;
    }

  3. Hello sir I got one issue like it’s like d pop up notification in which it gives web page is not available n I want to know what is the actual problem

  4. I was using WHATSAPP and suddenly it stop and shows net::ERR_UNKNOWN_URL_SCHEME. WHAT WILL I DO. Now I cannot downliad Whatsapp

  5. Viber on my cellphone couldn’t installed in spite repeatedly trying.Could you Pl.help.

  6. Salut am citit cu interes implementarea facuta de tine cum as putea face in cazul ca as dori sa deschis linkuri care incep cu “sop://” si “acestream://”
    daca ma poti ajuta iti multumesc anticipat

Leave a Reply

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