My provider will try to save a file using this
BaseFileSystem string: externalDataDirectory
My question is: If the user doesn’t have a SDCard the app will “automatically” save in another place (failsafe)? Like the internal memory?
I tested on 2 phones. One Nexus 5 (only internal memory) and another one with SDCard. The Nexus used his internal memory.
But I don’t know if is a standard way of android.
I’ll implement the appropriate failsafe, but I didn’t find this explanation in any place…
Hi,
On android you need to acquire permissions to use the SDcard. I use this function to acquire permissions by the user.
public getExternalPermissionGrant(){
return Observable.create((observer) => {
if(this._device.platform == "Android"){
this._diagnostic.isExternalStorageAuthorized().then(
(response: boolean) => {
if(response){
observer.next();
observer.complete();
} else {
this._diagnostic.requestExternalStorageAuthorization().then(
(authorization) => {
if(this._diagnostic.permissionStatus.GRANTED == authorization.READ_EXTERNAL_STORAGE){
this.setFileStorage().subscribe(
() => {
observer.next();
observer.complete();
},
(err) => {
console.error(err);
observer.error()
}
)
} else {
observer.next();
observer.complete();
}
}
).catch(
(err) => {
console.error(err);
observer.next();
observer.complete();
}
);
}
}
).catch(
(err) => {
console.error(err);
observer.next();
observer.complete();
}
);
} else {
observer.next();
observer.complete();
}
});
}
Then for obtain the SD path:
this._diagnostic.isExternalStorageAuthorized().then(
(response : boolean) => {
if(response){
this._diagnostic.getExternalSdCardDetails().then(
(details : Array<SdCardDetails>) => {
let sdPath: string = this._file_folder;
details.forEach(
(detail: SdCardDetails) => {
if (detail.canWrite){
sdPath = detail.filePath + "/";
}
}
)
this._is_external_active = true;
this._file_folder = sdPath;
console.info("DEVICE-FOLDER - Sd Card Details", details);
observer.next();
observer.complete();
}
).catch(
(err) => {
observer.error(err);
console.error("DEVICE-FOLDER", err);
}
)
} else {
console.info("DEVICE-FOLDER - Sd Card not found");
observer.next();
observer.complete();
}
}
);