I’m using the latest version of react-native-share (9.2.3) for sharing images from my app using share.open()
command.
The Share.open() works fine on IOS, but sharing options don’t open on Android 11 or greater, and no error is thrown as well.
Can anyone help me with this issue?
I converted PNGs stored in my project assets folder to URI using Image.resolveAssetSource(image).uri
command and then converted them to base64 format.
2
Answers
i think you have forgotten the provider options in Android
AndroidManifest.xml
copy and paste the below code in your
AndroidManifest.xml
Create a filepaths.xml under this directory:
copy and paste this code
for android sdk 30 or above follow this
The issue you are facing with react-native-share on Android 11 or greater might be related to changes in Android’s permission handling and file access restrictions.
Starting from Android 11, the file access permissions have become more restrictive, and you need to request additional permissions to access files outside your app’s private storage. When sharing images using react-native-share, the library might try to access files stored outside your app’s private storage, which could lead to permission issues and the sharing options not opening.
To fix this issue, you need to ensure that your app has the necessary permissions to access the files you want to share. In Android, you can use the READ_EXTERNAL_STORAGE permission to access files outside your app’s private storage. Additionally, you may need to use the MANAGE_EXTERNAL_STORAGE permission if you want to access files in a specific directory.
Here are the steps you can follow:
Update the AndroidManifest.xml to request the necessary permissions:
Request the MANAGE_EXTERNAL_STORAGE permission from the user at runtime (if required). Keep in mind that MANAGE_EXTERNAL_STORAGE is a dangerous permission and requires additional review on the Google Play Store.
Ensure that the image files you are trying to share are accessible by your app and located in a directory that your app has permission to access.
Convert the image to a base64 string and use react-native-share to share the image.
Keep in mind that accessing files outside your app’s private storage might require additional considerations for Android 11 or greater due to the new file access restrictions. Be sure to review the Android documentation on Scoped Storage and File Access Permissions for Android 11 to understand the best practices and limitations for file access in your app.
Also, consider using the latest version of react-native-share and checking the library’s documentation or GitHub repository for any specific updates or fixes related to Android 11 compatibility. If the issue persists, you may want to check for any open issues or discussions on the library’s GitHub page to see if other developers have encountered and resolved similar problems.