Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

WebView shows an error when a link opens another app, such as a Facebook link

Errornet::ERR_UNKNOWN_URL_SCHEME

Short answer

A WebView only loads web schemes. A link such as fb:// or intent:// makes the page fail, because loadUrl cannot open it. Catch the URL in shouldOverrideUrlLoading, send it to the system with an ACTION_VIEW intent, and return true. On Android 11 and newer, declare the scheme under queries.

  • Applies to Android 11 to 16, WebView with AndroidX, Kotlin and Java
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log every URL the WebView is asked to load. The failing one starts with something other than http or https.

    override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
        Log.d("WebView", "load: ${request.url}")
        return false
    }
  2. 2Match what you see, then jump to its fix

    1. 1The failing URL starts with fb://, intent:// or another app schemeYour WebViewClient lets the WebView load a non-web schemeFix
    2. 2The intent resolves to nothing even though the other app is installedOn Android 11 or newer your app cannot see the app that handles the linkFix

What does the error look like?

  • net::ERR_UNKNOWN_URL_SCHEME
  • ERROR_UNSUPPORTED_SCHEME
  • Unsupported URI scheme

Cause 1 of 2

Your WebViewClient lets the WebView load a non-web scheme

1Check

Android documents that shouldOverrideUrlLoading may be called with non-HTTP(S) schemes and that calling loadUrl with such a URL fails. If no WebViewClient is set, the WebView asks the Activity Manager to choose a handler instead.

adb logcat | grep -i webview

2Fix

In your WebViewClient, hand non-web schemes to the system. Return true so the WebView stops loading the URL, and return false for normal http and https pages.

webView.webViewClient = object : WebViewClient() {
    override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
        val uri = request.url
        if (uri.scheme == "http" || uri.scheme == "https") return false
        try {
            view.context.startActivity(Intent(Intent.ACTION_VIEW, uri))
        } catch (e: ActivityNotFoundException) {
            // no app handles this scheme: ignore it or show a message
        }
        return true
    }
}

3Verify

Tap the link. The other app opens, and the WebView stays on its page without an error.

adb logcat | grep -i ActivityNotFound

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 2

On Android 11 or newer your app cannot see the app that handles the link

1Check

When targetSdk is 30 or higher, the system filters out apps your app has not declared. A resolveActivity check can return null even when a handler exists.

grep -n "queries" app/src/main/AndroidManifest.xml

2Fix

Declare the intent signature you open in a queries element of the manifest.

<manifest ...>
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="fb" />
        </intent>
    </queries>
</manifest>

3Verify

Rebuild, install and tap the link again.

./gradlew installDebug

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Always return false for http and https in shouldOverrideUrlLoading, and never call loadUrl with the same URL and return true.
  • Wrap startActivity in a try and catch ActivityNotFoundException, because the user may not have the app.
  • Check only the schemes you expect instead of opening every URL the page offers.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.