Reputation: 51
I'm trying to read directories and files from a folder on the external SD-Card on Android. cordova.file.externalRootDirectory
is returning file:///storage/emulated/0/
which is not the path of the SD-Card.
Using cordova.plugins.diagnostic.getExternalSdCardDetails()
I got the root path of my SD-Card but if I try to read it, it returns FileError code: 5
.
Cordova Version: 9.0.0 ([email protected]) Android-API Level: 22
cordova.plugins.diagnostic.getExternalSdCardDetails(function(data) {
window.resolveLocalFileSystemURL(data[0].filePath + "/",
$scope.onFSSuccess, $scope.onError);
}, console.log);
$scope.onError is triggered returning error 5.
this.onError = function(e) {
console.log(e);
}
Function which should create reader of SD-Card folder.
this.onFSSuccess = function(fileSystem) {
fs = fileSystem;
var directoryReader = fileSystem.createReader();
directoryReader.localURL = directoryReader.localURL + $scope.dirPath;
$scope.directoryReaderPath = directoryReader.localURL;
directoryReader.readEntries($scope.readerSuccess, $scope.onError);
}
NOTE: i added the following lines to the config.xml
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Update: I tried using an absolute path. file:///storage/sdcard/0/
Still not working.
Upvotes: 5
Views: 693