Skip to content

Fix Android document opening silently failing (PDF and others) - #21

Draft
fabio21 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-open-document-pdf-android
Draft

Fix Android document opening silently failing (PDF and others)#21
fabio21 with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-open-document-pdf-android

Conversation

CopilotAI commented May 25, 2026

Copy link
Copy Markdown

On Android, calling openDocument() silently did nothing — no error, no viewer launched — while iOS worked fine. Three bugs combined to cause this.

Root causes & fixes

  • ClassCastException killing the activity reference (OpenDocumentPlugin.kt): binding.activity as FlutterActivity throws when the host app uses FlutterFragmentActivity (standard modern Flutter setup), leaving activity = null. The null-safe ?.startActivity(intent) then silently no-ops. Fixed by using android.app.Activity throughout — no cast needed since ActivityPluginBinding.getActivity() already returns Activity.

    // Before — crashes silently for FlutterFragmentActivity hosts
    it?.setActivity(binding.activity asFlutterActivity)
    // After
    it?.setActivity(binding.activity)
  • result.success() never called (OpenDocument.kt): After startActivity, neither result.success() nor result.error() was invoked on the happy path, so the Dart await would never resolve.

  • Wrong file extension for multi-dot filenames: name(url).split(".")[1] picks index 1, so my.report.pdf → MIME type for report instead of pdf. Changed to substringAfterLast(".").

  • FLAG_ACTIVITY_SINGLE_TOPFLAG_ACTIVITY_NEW_TASK: Ensures the viewer launches correctly when called from a background thread.

… result.success(), fix extension parsing
Agent-Logs-Url: https://github.com/fabio21/open_document/sessions/a7bb8ad9-0a8a-4bc2-a382-470541dd33fa
Co-authored-by: fabio21 <8049768+fabio21@users.noreply.github.com>
CopilotAI changed the title [WIP] Fix open_document not opening PDF file on AndroidFix Android document opening silently failing (PDF and others)May 25, 2026
CopilotAI requested a review from fabio21May 25, 2026 11:21
Sign up for freeto 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.

open_document not opening pdf file at Android but working good on iOS

2 participants

@fabio21