Skip to content

‘Err_unknown_URL_scheme’ in Android Webview: 3 Fixes

Android is by far the most popular smartphone operating system in the world. This also means that Android development is abundant and relatively easy to do now. However, random bugs and errors are nothing new for a programmer. 

This article discusses the “Err_unknown_URL_scheme’ in Android Webview” error and gives three solutions to fix the problem. 

Also read: Content://com.android.browser.home: Explained


Open external links in a new tab

While it isn’t exactly best practice in development to open external links in new tabs, the method can get you around this error. All you have to do is add target=”_blank” in your anchor tag, and you’re good to go. 

<a href="https://candid.technology" target="_blank">Visit Candid.Technology</a>

Add another intent

Android apps use intents to tell the app what to do when a call to action happens. You can write code to detect the intent and act accordingly. The snippet below ignores any URL starting with HTTP:// or HTTPS:// and instead uses the intent to perform a particular action. 

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url == null || url.startsWith("http://") || url.startsWith("https://")) {
        return false;
    } 

    try {
        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;
    }
}

Also read: What is ‘com android settings intelligence’?


Disable non-standard URLs

This method works the exact opposite way of the previous one. Here, you can bypass the issue by simply disabling non-standard URLs. This means that instead of getting the Err_unknown_URL_scheme’ in Android Webview error, you’ll have an unknown link type error instead of telling the user they can’t proceed. 

@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, "Error: Unknown link type", Toast.LENGTH_SHORT).show();
}
return false;
}

Also read: Error displaying widget: model not found: 5 Fixes

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.

We may earn a commission if you buy something from a link on this page. Thanks for your support.







>