0

I have an ionic angular app and need to share a .gpx file via gmail or whatsapp. It works smoothly via gmail. Also via wechat, but not via whatsapp.

I tried with capacitor share, where I can select gmail, whatsapp, wechat, ...

await Share.share({
  title: this.translate.instant('ARCHIVE.TITLE'),
  text: this.translate.instant('ARCHIVE.TEXT'),
  files: [uri.uri],   // public file path
  dialogTitle: this.translate.instant('ARCHIVE.DIALOG_TITLE'),
});

and works with gmail and wechat, but not with whatsapp. I moved to cordova socialsharing without any success. In principle, I allocated my file in cache directory, but also tested other options of external storage.


I managed to send images: 1) I save the images on the external cache folder using capacitor/filesystem, 2) I get the files uri with the same plugin and 3) I share the files using cordova social-sharing. Nevertheless, the method does not work for .gpx (xml) files

0

1 Answer 1

0

I have finally managed to share via whatsapp the two types of files I needed to: png images and gpx (xml) files. You have to bear in mind that the method is probably not universal and may not work for certain files. In both cases, I first saved the file to the external cache folder using capacitor's filesystem:

      const savedFile = await Filesystem.writeFile({
        path: file,       
        data: gpxText,
        directory: Directory.ExternalCache,
        recursive: true,
        encoding: Encoding.UTF8,
      });

Then, I share the file URI using Cordova's Social Sharing.

      await this.socialSharing.shareWithOptions({
        files: [savedFile.uri],
        chooserTitle: '...'
      });

However, in the case of the gpx file, you can send just the file, without any text. If you try to send both text and file, the transfer fails. ChatGPT suggests that this may be due to the following:

  1. Some sharing plugins (cordova-plugin-x-socialsharing, Capacitor Share API, etc.) treat a text + file share differently than a file-only share.

  2. On Android, if you only provide a file (with a valid MIME type, e.g. application/gpx+xml or application/octet-stream), the system share sheet is more likely to open correctly and show WhatsApp.

  3. When you add a message or text, certain apps (like WhatsApp) may try to interpret the share as a text-only share, which then hides the file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.