WebView shows an error when a link opens another app, such as a Facebook link
net::ERR_UNKNOWN_URL_SCHEMEShort 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.
Fix it fast
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 }2Match what you see, then jump to its fix
What does the error look like?
net::ERR_UNKNOWN_URL_SCHEMEERROR_UNSUPPORTED_SCHEMEUnsupported 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 webview2Fix
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 ActivityNotFoundConfirmed by developer.android.com
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.xml2Fix
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 installDebugConfirmed by developer.android.com
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:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
getUserMedia fails in an Android WebView with no permission prompt
no permission dialog appears when the page calls getUserMedia
A WebView never shows the camera prompt by itself.
3 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fixMobile apps
Java and Kotlin compile to different JVM targets in an Android module
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17)
Java and Kotlin tasks in the same module are compiling for different JVM targets, for example 1.8 and 17.
2 causes, each with a fix