I'm trying to save an image to external storage on Android 8.0.0 but the write always fails, the code works fine on Android below 8. I've requested the storage permission, the app has permission to read and write to external storage
var imageBlob = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "test.png");
var external = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory);
if (Ti.Filesystem.isExternalStoragePresent()) { //returns true
Ti.API.info("external storage present");
if (!external.exists()) { //returns false
if (external.createDirectory()) { //returns false
Ti.API.info("directory created");
} else {
Ti.API.info("error creating dir");
}
Ti.API.info("external.exists= " + external.exists());
}else{
var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "original.png");
if(file.exists()){ //returns true
if(imageBlob.write(file.read())){ //returns false
Ti.API.info("image saved");
}
}
}
}
Edit: Thanks to the help of one of TiSlack members I was able to solve the issue instead of using Ti.Filesystem.requestStoragePermissions to request storage permission I used
var permissions = ['android.permission.WRITE_EXTERNAL_STORAGE'];
Ti.Android.requestPermissions(permissions, function(e) {...})