Repository navigation
fix(share): launch share target with NEW_TASK flag on Android - #2608
Open
hungle-innova wants to merge 1 commit into
Open
hungle-innova wants to merge 1 commit into
hungle-innova wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 processEXTRA_TEXTwhen launched viastartActivityForResultwithoutFLAG_ACTIVITY_NEW_TASK.Changes:
Intent.FLAG_ACTIVITY_NEW_TASKto the share intent, allowing the target application to launch in its own task stack properly.getActivity().startActivity(chooser)instead ofstartActivityForResult(call, chooser, "activityResult").callwith an empty object upon launching the chooser.Change Type
Rationale / Problems Fixed
Problem:
When sharing text or links using
@capacitor/shareon 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:
singleTaskor specific task affinity).startActivityForResult(call, chooser, "activityResult"). WhenstartActivityForResultis used, the chooser passes the for-result mode to the target app, binding it to the caller's task stack.singleTaskactivity for result withoutIntent.FLAG_ACTIVITY_NEW_TASKleads to intent extras (EXTRA_TEXT) being dropped or ignored during task transition.FLAG_ACTIVITY_NEW_TASKwithstartActivityForResult(which immediately returnsRESULT_CANCELED).Solution:
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.getActivity().startActivity(chooser)avoids thestartActivityForResultconstraint and enables seamless sharing into apps that enforce task isolation.Tests or Reproductions
Reproduction Steps:
Share.share({ title: 'Title', text: 'Check this out:', url: 'https://example.com' })."Check this out: https://example.com".Tested Devices:
Platforms Affected