Skip to content

Handle missing handler for external links in DocViewerActivity - #47

Closed
jim-daf wants to merge 1 commit into
Peace-Ray:mainfrom
jim-daf:fix/docviewer-external-link-crash
Closed

jim-daf wants to merge 1 commit into
Peace-Ray:mainfrom
jim-daf:fix/docviewer-external-link-crash

Conversation

@jim-daf

@jim-daf jim-daf commented Jun 4, 2026

Copy link
Copy Markdown

What

DocViewerActivity.overrideUrlLoading sends ://-scheme links to an external app with a raw startActivity(Intent(Intent.ACTION_VIEW, ...)). When no installed app can open the link that call throws ActivityNotFoundException and the viewer crashes.

This wraps the launch in a try/catch and shows a short toast when nothing can open the link. The mailto: branch already goes through Intent.createChooser, so it is left as is. Links that resolve behave exactly as before.

Changes

                 val uri = Uri.parse(path)
                 val intent = Intent(Intent.ACTION_VIEW, uri)
-                startActivity(intent)
+                try {
+                    startActivity(intent)
+                } catch (e: ActivityNotFoundException) {
+                    Toast.makeText(
+                        this@DocViewerActivity,
+                        getString(R.string.document_viewer_no_app_for_link),
+                        Toast.LENGTH_SHORT
+                    ).show()
+                }
                 true

A document_viewer_no_app_for_link string is added alongside the existing document_viewer_* entries.

Closes #46

When the document viewer routes an http(s) or other ://-scheme link out
with startActivity(ACTION_VIEW) and no app on the device can open it, the
call throws ActivityNotFoundException and the activity crashes.

Wrap the launch in a try/catch and show a short toast when nothing can
open the link.
@jim-daf

jim-daf commented Jun 4, 2026

Copy link
Copy Markdown
Author

Closing this, it duplicates #45. Apologies for the noise.

@jim-daf jim-daf closed this Jun 4, 2026
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.

Document viewer can crash with ActivityNotFoundException on external links

1 participant