@capacitor/share
The Share API provides methods for sharing content in any sharing-enabled apps the user may have installed.
The Share API works on iOS, Android, and the Web (using the new Web Share API), though web support is currently spotty.
Install
npm install @capacitor/share
npx cap sync
Android
By default, Capacitor apps only allow to share files from caches folder. To make other Android folders shareable, they have to be added in android/app/src/main/res/xml/file_paths.xml
file. Check the Specifying Available Files section in FileProvider docs for the available locations.
Example
import { Share } from '@capacitor/share';
await Share.share({
title: 'See cool stuff',
text: 'Really awesome thing you need to see right meow',
url: 'http://ionicframework.com/',
dialogTitle: 'Share with buddies',
});
// Share text only
await Share.share({
text: 'Really awesome thing you need to see right meow',
});
// Share url only
await Share.share({
url: 'http://ionicframework.com/',
});
// Share local file using url parameter
const photo = await Camera.getPhoto(options);
await Share.share({
url: photo.path,
});
// Share multiple files using files parameter
const { photos } = await Camera.pickImages(options);
await Share.share({
files: photos.map(photo => photo.path!),
});