Skip to content

fix(share): keep the common MIME type when sharing several files on Android - #2618

Open
RaphaelFakhri wants to merge 1 commit into
ionic-team:mainfrom
RaphaelFakhri:fix/share-android-multi-file-mime-type
Open

RaphaelFakhri wants to merge 1 commit into
ionic-team:mainfrom
RaphaelFakhri:fix/share-android-multi-file-mime-type

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Closes #2605

Description

On Android, shareFiles sets the intent type to */* as soon as more than one file is shared, even when every file has a known MIME type. Issue #2605 reports that WhatsApp treats such a */* ACTION_SEND_MULTIPLE intent as text-only and sends only the text.

This change sets the intent type to the most specific type that covers every shared file:

  • The type itself when all files have the same MIME type, for example image/jpeg.
  • <type>/* when the files share only the top-level type, for example image/* for a JPEG and a PNG.
  • */* when the top-level types differ or any type is unknown, as before.

Single-file shares keep their current behavior.

Testing

  • Added SharePluginTest, a JVM unit test for the new getCommonMimeType helper.
  • ./gradlew testDebugUnitTest --tests "com.capacitorjs.plugins.share.*" in share/android: 3 tests pass.
  • ./gradlew clean build test in share/android passes.
  • npx prettier --check "android/src/**/*.java" --plugin=prettier-plugin-java in share passes.

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.

[@capacitor/share] Android: sharing several images with text to WhatsApp only sends the text (intent type forced to */*)

1 participant