react native share in android 11 or above

60 views Asked by At

I used react native scoped storage and getting image perfectly but when i share it to whatsapp I got error file format not supported my code is.

<TouchableOpacity
    style={[styles.button, {marginRight: 10}]}
    onPress={shareImage}>
    <View style={styles.iconContainer}>
      <Image
        source={require('../assets/share1.png')}
        resizeMode="contain"
        style={styles.icon}
      />
      <Text style={styles.actions} adjustsFontSizeToFit numberOfLines={1}>
        Share
      </Text>
    </View>
  </TouchableOpacity>
const shareImage = async () => {
try {
  console.log(props.source.uri)
  const shareOptions = {
    title: 'Share Image',
    url: `${props.source.uri}`, // Use file:// prefix with the file path
  };
  const shareResponse = await Share.open(shareOptions); // Use open() instead of share()
  console.log('Share Response', shareResponse);
} catch (error) {
  console.error('Error sharing image:', error);
}
}

whereas props.source.uri is something like that

content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2

I loaded image with the help of react native scoped storage but when i try to share them i got file format is not supported so tell me how to share that kind of uri.

0

There are 0 answers