Skip to content

fix(privacy-policy): route non http(s) links out of the WebView#165

Open
jim-daf wants to merge 1 commit into
opencloud-eu:mainfrom
jim-daf:fix/privacy-policy-webview-url-routing
Open

fix(privacy-policy): route non http(s) links out of the WebView#165
jim-daf wants to merge 1 commit into
opencloud-eu:mainfrom
jim-daf:fix/privacy-policy-webview-url-routing

Conversation

@jim-daf
Copy link
Copy Markdown

@jim-daf jim-daf commented May 16, 2026

Closes #164.

PrivacyPolicyActivity.onCreate sets up the WebViewClient with only an onReceivedError override, so any link in the privacy policy with a non http(s) scheme (mailto:, tel:, intent:, market:, geo:, ...) is dispatched by the default WebView handler instead of leaving the WebView for the system app that registered for that scheme. The visible effect is that tapping a mailto: link in the policy text shows nothing.

Change

Override shouldOverrideUrlLoading. Keep http(s) inside the WebView, route other schemes to Intent.ACTION_VIEW, and wrap the launch in try/catch (ActivityNotFoundException) so a device with no handler does not crash the Activity:

override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
    val url = request?.url ?: return false
    val scheme = url.scheme?.lowercase()
    if (scheme == "http" || scheme == "https") return false
    return try {
        val intent = Intent(Intent.ACTION_VIEW, url).apply {
            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }
        startActivity(intent)
        true
    } catch (e: ActivityNotFoundException) {
        false
    }
}

Behaviour

  • A normal https://opencloud.eu/privacy link inside the policy keeps loading in the WebView like before.
  • A mailto:legal@opencloud.eu link now opens the user's mail app.
  • A scheme nothing on the device handles falls through to false so the user does not see a crash.

The PrivacyPolicyActivity WebView only configures onReceivedError, so any
link in the rendered privacy policy with a non http(s) scheme (mailto:,
tel:, intent:, market:, geo:, ...) is dispatched to the WebView's default
handler. Override shouldOverrideUrlLoading to keep http(s) inside the
WebView and route other schemes out via Intent.ACTION_VIEW, catching
ActivityNotFoundException so the Activity does not crash if no handler is
installed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PrivacyPolicyActivity WebView does not route non http(s) links out of the WebView

1 participant