I am working on an Ionic React app where I need to download a certificate image. Recently, we encountered a bug where the certificate is not downloading and gives an error. Upon investigating, we found that this issue only occurs in Android 13 (compileSdkVersion 33). It could possibly be related to permissions in Android 13. I have read many forums and blogs on this topic, but I haven’t found any feasible solutions yet.
AndroidManifest.xml permissions
Permissions →
uses-permission android:name=“android.permission.READ_EXTERNAL_STORAGE”/>
uses-permission android:name=“android.permission.WRITE_EXTERNAL_STORAGE” />
uses-permission android:name=“android.permission.INTERNET” />
and Here is the code snippet
const base64Data = await base64FromPath(res.data);
const savedFile = await Filesystem.writeFile({
path: `Report_of_authenticity_${orderDetail.jobId}.png`,
data: base64Data,
directory: Directory.Cache,
});
console.log("saved file cert", savedFile);
const albumName = "TEST";
let albumIdentifier: any = "";
if (isPlatform("ios")) {
// Handle albums
let albums = await Media.getAlbums();
albumIdentifier =
albums.albums.find((a) => a.name === albumName) || null;
if (!albumIdentifier) {
// Doesn't exist, create new album
await Media.createAlbum({ name: albumName });
albums = await Media.getAlbums();
albumIdentifier = albums.albums.find(
(a) => a.name === albumName
);
}
}
// else if (isPlatform("android")) {
// await Media.createAlbum({ name: albumName });
// }
console.log("cert albumIdentifier", albumIdentifier);
Media.savePhoto({
path: savedFile.uri,
album: isPlatform("ios")
? albumIdentifier
: {
name: albumName,
},
})
.then(() => {
console.log("cert Image has been saved");
present("File has been downloaded", TOAST_TIMER);
setIsDownloadingCert(false);
})
.catch((e) => {
console.error("cert error", e);
present("Error downloading file", TOAST_TIMER);
setIsDownloadingCert(false);
});
Error Is=>
Error: Unable to do file operation, user denied permission request