Skip to content

fix(share): launch share target with NEW_TASK flag on Android - #2608

Open
hungle-innova wants to merge 1 commit into
ionic-team:mainfrom
hungle-innova:fix/share-android-new-task
Open

hungle-innova wants to merge 1 commit into
ionic-team:mainfrom
hungle-innova:fix/share-android-new-task

Conversation

@hungle-innova

@hungle-innova hungle-innova commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

Fixes an issue on Android where sharing text/URLs (EXTRA_TEXT) to certain messaging applications (such as Google Chat, Slack, etc.) leaves the message compose input empty.

This happens because target apps with launchMode="singleTask" or separate task affinities do not receive or process EXTRA_TEXT when launched via startActivityForResult without FLAG_ACTIVITY_NEW_TASK.

Changes:

  1. Add Intent.FLAG_ACTIVITY_NEW_TASK to the share intent, allowing the target application to launch in its own task stack properly.
  2. Launch the chooser using getActivity().startActivity(chooser) instead of startActivityForResult(call, chooser, "activityResult").
  3. Resolve call with an empty object upon launching the chooser.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation
  • Other (CI, chores, etc.)

Rationale / Problems Fixed

Problem:

When sharing text or links using @capacitor/share on Android (especially reproducible on Android 14, 15, and 16, e.g. Google Pixel devices), selecting Google Chat from the system share sheet opens Google Chat's conversation picker, but once a conversation is selected, the message composer is completely blank. The user has nothing to send. In contrast, apps like Gmail work as expected.

Root Cause:

  • Many messaging apps (including Google Chat) define their sharing activities to run in their own tasks (singleTask or specific task affinity).
  • Capacitor currently launches the share chooser via startActivityForResult(call, chooser, "activityResult"). When startActivityForResult is used, the chooser passes the for-result mode to the target app, binding it to the caller's task stack.
  • In Android, launching an external singleTask activity for result without Intent.FLAG_ACTIVITY_NEW_TASK leads to intent extras (EXTRA_TEXT) being dropped or ignored during task transition.
  • Furthermore, Android explicitly forbids combining FLAG_ACTIVITY_NEW_TASK with startActivityForResult (which immediately returns RESULT_CANCELED).

Solution:

  • Adding intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ensures the receiving activity is launched in its own task and receives all intent extras (EXTRA_TEXT, EXTRA_SUBJECT, etc.) correctly.
  • Using getActivity().startActivity(chooser) avoids the startActivityForResult constraint and enables seamless sharing into apps that enforce task isolation.

Tests or Reproductions

  • Reproduction Steps:

    1. Call Share.share({ title: 'Title', text: 'Check this out:', url: 'https://example.com' }).
    2. In Android share sheet, select Google Chat.
    3. Select any conversation.
    4. Before fix: Message text input is empty.
    5. After fix: Message text input is populated with "Check this out: https://example.com".
  • Tested Devices:

    • Google Pixel (Android 16 & Android 15)
    • Samsung Galaxy (Android 14)
    • Verified with Google Chat, Gmail, Google Keep, Slack, and Messages.

Platforms Affected

  • Android
  • iOS
  • Web

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.

2 participants