Skip to content

fix(docviewer): guard mailto / external-link launches with try/catch - #45

Open
jim-daf wants to merge 1 commit into
Peace-Ray:mainfrom
jim-daf:fix-docviewer-startactivity
Open

jim-daf wants to merge 1 commit into
Peace-Ray:mainfrom
jim-daf:fix-docviewer-startactivity

Conversation

@jim-daf

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

Copy link
Copy Markdown

Closes #44.

DocViewerActivity.overrideUrlLoading routes mailto: and external :// URLs out through raw startActivity calls. If nothing on the device handles the link (no mail client for mailto:, no browser, kiosk / car-headunit-style devices) startActivity raises ActivityNotFoundException and DocViewerActivity crashes mid-tap.

Run both launches through a small launchExternal helper that catches ActivityNotFoundException and surfaces a Toast (document_viewer_no_app_for_link) instead:

private fun launchExternal(intent: Intent) {
    try {
        startActivity(intent)
    } catch (e: ActivityNotFoundException) {
        Toast.makeText(this@DocViewerActivity, R.string.document_viewer_no_app_for_link, Toast.LENGTH_SHORT).show()
    }
}

Adds a document_viewer_no_app_for_link string so the message stays translatable. The happy path (a URL with a viewer installed) is unchanged.

DocViewerActivity.overrideUrlLoading routes mailto: links and any
URL with a scheme ("://" path) out through raw startActivity calls.
If the device has no app that can handle the link (no mail client,
no browser, custom scheme) startActivity raises
ActivityNotFoundException and DocViewerActivity crashes mid-tap.

Run both launches through a small launchExternal helper that
catches the exception and shows a short Toast
(document_viewer_no_app_for_link) instead. Happy path is unchanged.
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.

DocViewerActivity crashes when no app handles a tapped link

1 participant