feat(share_plus): add Android Save Action#3914
Open
vchrisb wants to merge 1 commit into
Open
Conversation
Add an opt-in Save action when sharing files through the Android 14+ Sharesheet. Use Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS because it is Android's closest native equivalent to the Save option provided by the iOS share sheet. Save images to Pictures, videos to Movies, and other files to Downloads through MediaStore without requiring storage permission. Support localized progress and result labels, preserve request-scoped cache files during asynchronous saves, and roll back partially saved batches on failure. Ignore the option on older Android versions, other platforms, and shares without files. Document the API and add platform-interface and Android instrumentation coverage.
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
Adds an opt-in Save action to the Android Sharesheet when sharing files, providing an experience similar to the native Save option available in the iOS share sheet.
This PR:
androidIncludeSaveActionand customizableAndroidSaveActionLabelstoShareParams.MediaStore.Why
EXTRA_CHOOSER_CUSTOM_ACTIONS?Android does not provide an equivalent Save option in its default Sharesheet.
Intent.EXTRA_CHOOSER_CUSTOM_ACTIONSis the official extension point that most closely matches the native iOS experience: Save appears directly in the system Sharesheet alongside its other actions, instead of being presented as a separate share target or custom Flutter UI.This API is only available on Android 14 (API level 34) and later. On older Android versions, other platforms, or shares without files, the option is ignored gracefully.
ShareResultsemanticsThe returned
ShareResultreports the user’s interaction with the Sharesheet, including selection of the Save action. It does not wait for or report the result of the asynchronous MediaStore copy.Saving progress and completion are handled natively on Android through the progress activity and a success or failure message.
Why does
Share.ktcontain many changes?The Save action does not copy files inside the original
share()call. Selecting it launches a native activity that performs the MediaStore copy on a background executor, and that copy may take some time.Share.kttherefore needs to manage the shared files for the lifetime of the asynchronous save:Alternative considered
One alternative would be to expose arbitrary
EXTRA_CHOOSER_CUSTOM_ACTIONSthroughShareParamsand notify Flutter when an action is selected. The application developer would then implement the selected action’s behavior.Another option is not to provide a Save action in
share_plusat all. Developers would instead build a Flutter UI that lets users choose between sharing and saving before opening the system Sharesheet. Sharing would remain handled byshare_plus, while saving would require a separate package or application-specific implementation.These approaches keep file saving outside the scope of
share_plusand offer more flexibility, but they do not provide an integrated native Sharesheet experience. They also require each application to implement its own UI, file handling, localization, progress reporting, and error handling.This PR instead provides a focused, ready-to-use Save action that behaves consistently and more closely matches the native iOS share-sheet experience.
Related Issues
Checklist
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles.flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
!in the title as explained in Conventional Commits).