'Is it possible to share both text message and image using expo-sharing?
Sharing.shareAsync(url, options)
Opens action sheet to share file to different applications which can handle this type of file.
Arguments url (string) -- Local file URL to share. options (object) -- A map of options: mimeType (string) -- sets mimeType for Intent (Android only) dialogTitle (string) -- sets share dialog title (Android and Web only) UTI (string) -- (Uniform Type Identifier) the type of the target file (iOS only)
This is what they say on their page. I dont see any option to share text message along with a local image. Is there any way to share both the image and text message ?
Solution 1:[1]
According to the docs, you should be able to use it like so for Android:
url = '<image-to-be-shared-local-url>';
messageText = 'Text that you want to share goes here';
const options = {
mimeType: 'image/jpeg',
dialogTitle: messageText,
};
Sharing.shareAsync(url, options);
But I would recommend to use react-native-share as this is more widely used and has more options for you to experiment with.
Here is the library documentation
Hope this helps :)
Solution 2:[2]
react-native-share still not compatible with expo. you have to use either expo-sharing or Share from react-native.
Example:
ShareMessage = async () => {
if (Platform.OS === "android") {
Share.share({
message: API.base_url + this.state.ShareProductName, // supporting android
url: this.state.share_images[0], // not supporting
title: this.state.ShareProductName,
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
} else if (Platform.OS === "ios") {
Share.share({
message:API.base_url + this.state.ShareProductName,
url: this.state.share_images[0],
title: this.state.ShareProductName, // not supporting
})
.then((result) => console.log(result))
.catch((errorMsg) => console.log(errorMsg));
return;
}
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
