Skip to content

Catch ActivityNotFoundException when opening external WebView links#132

Merged
chenxiaolong merged 1 commit into
chenxiaolong:masterfrom
jim-daf:fix-external-link-crash
May 16, 2026
Merged

Catch ActivityNotFoundException when opening external WebView links#132
chenxiaolong merged 1 commit into
chenxiaolong:masterfrom
jim-daf:fix-external-link-crash

Conversation

@jim-daf
Copy link
Copy Markdown
Contributor

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

Closes #131.

What changes

WebUiActivity.kt's shouldOverrideUrlLoading calls startActivity(Intent(Intent.ACTION_VIEW, uri)) to hand off external links (Syncthing docs, forum, etc.) to a system browser. If no installed app can handle that intent, startActivity raises ActivityNotFoundException and the activity crashes.

This wraps the call in a try / catch (ActivityNotFoundException) and logs a warning. The click becomes a silent no-op instead of a crash, which is the standard outcome when there is no browser registered.

 override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
     val uri = request.url
     val guiUri = guiUri

     if (uri.scheme == guiUri.scheme && uri.host == guiUri.host && uri.port == guiUri.port) {
         return false
     } else {
-        startActivity(Intent(Intent.ACTION_VIEW, uri))
+        try {
+            startActivity(Intent(Intent.ACTION_VIEW, uri))
+        } catch (e: ActivityNotFoundException) {
+            Log.w(TAG, "No app installed to handle $uri", e)
+        }
         return true
     }
 }

android.content.ActivityNotFoundException is added to the imports. Nothing else moves.

@chenxiaolong chenxiaolong self-assigned this May 16, 2026
Copy link
Copy Markdown
Owner

@chenxiaolong chenxiaolong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@chenxiaolong chenxiaolong merged commit 42a39d1 into chenxiaolong:master May 16, 2026
1 check passed
chenxiaolong added a commit that referenced this pull request May 16, 2026
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
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.

WebUiActivity can crash with ActivityNotFoundException when following external links

2 participants