Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#2,605 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, java
Ambito
mobile

Direzione di ricerca

Start at the SharePlugin.shareFiles entry point and inspect how MIME types and ACTION_SEND_MULTIPLE intents are built. Reproduce the issue with several JPEG URIs and text, then verify that WhatsApp receives every image and the text while mixed or unknown types retain the documented fallback behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

platform: android

Bug Report

Plugin(s)

@capacitor/share 8.0.2

Capacitor Version
Latest Dependencies:
  @capacitor/cli: 8.5.2
  @capacitor/core: 8.5.2
  @capacitor/android: 8.5.2
  @capacitor/ios: 8.5.2
Installed Dependencies:
  @capacitor/ios: not installed
  @capacitor/cli: 8.5.2
  @capacitor/core: 8.5.2
  @capacitor/android: 8.5.2
Platform(s)

Android

Current Behavior

Sharing several image files together with a text to WhatsApp only delivers the text: WhatsApp drops all the images. Sharing a single image with the same text works.

In SharePlugin.shareFiles, the intent type is forced to */* as soon as more than one file is shared, even when every file has a known MIME type:

String type = getMimeType(file);
if (type == null || filesList.size() > 1) {
    type = "*/*";
}
intent.setType(type);

With three JPEG files, the ACTION_SEND_MULTIPLE intent is sent as */*, and WhatsApp treats it as a text-only share.

We confirmed it on a physical Android phone. Our logs showed the three files written to the cache and passed to Share.share, the plugin resolving with activityType: com.whatsapp, and still only the text reaching the conversation.

Expected Behavior

The intent should carry the common MIME type of the shared files, as Chrome's Web Share does: image/jpeg when all files are JPEG, image/* when they are mixed image types, and */* only when the types differ or are unknown. WhatsApp then receives all the images with the text.

Code Reproduction
import { Directory, Filesystem } from '@capacitor/filesystem'
import { Share } from '@capacitor/share'

// three small JPEGs written to the cache
const uris = []
for (const name of ['a.jpg', 'b.jpg', 'c.jpg']) {
  const { uri } = await Filesystem.writeFile({ path: `share/${name}`, data: JPEG_BASE64, directory: Directory.Cache, recursive: true })
  uris.push(uri)
}
await Share.share({ text: 'Three photos', files: uris })
// choose WhatsApp → only "Three photos" is sent
// with files: [uris[0]] → the photo and the text are sent
Other Technical Details

The following change fixes it for us. We apply it with patch-package, and three images plus the text now reach WhatsApp:

-                    String type = getMimeType(file);
-                    if (type == null || filesList.size() > 1) {
-                        type = "*/*";
-                    }
-                    intent.setType(type);
+                    String type = getMimeType(file);
+                    if (type == null) {
+                        sharedType = "*/*";
+                    } else if (sharedType == null) {
+                        sharedType = type;
+                    } else if (!sharedType.equals(type)) {
+                        boolean bothImages = sharedType.startsWith("image/") && type.startsWith("image/");
+                        sharedType = bothImages ? "image/*" : "*/*";
+                    }
+                    intent.setType(sharedType);

(sharedType is a String declared as null before the loop.)

We also set a ClipData covering every URI for ACTION_SEND_MULTIPLE, since the plugin currently only does it for a single file. That was not enough on its own: the MIME type was the deciding factor.

if (fileUris.size() > 1) {
    ClipData clipData = ClipData.newRawUri("", fileUris.get(0));
    for (int i = 1; i < fileUris.size(); i++) {
        clipData.addItem(new ClipData.Item(fileUris.get(i)));
    }
    intent.setClipData(clipData);
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
}

Related: #2474 (unknown extensions also fall back to */*, which WhatsApp likewise discards).

Lingua principale
Java
Stelle
685
Fork
691
Merge medio
16h 33m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor-plugins

Tutte le issue di ionic-team/capacitor-plugins

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.