The image stored in FirbaseStorage, and its link stored in FirebaseDatarealtime which look like this:
(https://i.stack.imgur.com/AsCrC.png)
then showed the image to user using Glide and when the user click on the image a new intent created for sharing the image and the code gose like this:
imageUrl = the image url stored in Firebase Datarealtime
StorageReference storageRef = FirebaseStorage.getInstance().getReferenceFromUrl(imageUrl);
storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String downloadUrl = uri.toString();
shareImage(downloadUrl);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
private void shareImage(String downloadUrl) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(downloadUrl));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share Image"));
}
The resule : " The File formate is not supported "
I want to be able to share these images which stored in FirebaseStorage by grabing its links from Firebase Datarealtime, and share them in social apps like whatsapp, facebook app, etc.
It looks like you're almost there! The error "The File format is not supported" typically occurs when the URI you're trying to share is not in the correct format for the sharing intent. Instead of using
Uri.parse(downloadUrl), you should create aFileProviderURI for the file and use that in the sharing intent. Here's how you can modify your code to achieve this:First, make sure you have a
FileProviderconfigured in yourAndroidManifest.xml:Then, create a
file_paths.xmlfile in yourres/xmldirectory with the following content:Next, modify your code to use
FileProvider.getUriForFile():This code will download the image file to a temporary location and create a
FileProviderURI for sharing. Note that this approach will download the image every time you share it. If you want to avoid unnecessary downloads, you can implement caching logic to store the images locally after the first download.