cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Not seeing any files on the android device

Open premtemp1 opened this issue 6 years ago • 2 comments

Hello, I trying to read android folder and show the user a list of files but I am NOT seeing any files that I have uploaded in any folders.

  var localURLs = [
                cordova.file.applicationDirectory,
                cordova.file.applicationStorageDirectory,
                cordova.file.cacheDirectory,
                cordova.file.dataDirectory,
                cordova.file.externalRootDirectory , 
                cordova.file.externalApplicationStorageDirectory,
                cordova.file.externalCacheDirectory,
                cordova.file.externalDataDirectory

            ];
            var index = 0;
            var i;
            var errorStr = '';
            var fileList = [];
            var addFileEntry = function (entry) {
                var dirReader = entry.createReader();
                dirReader.readEntries(
                    function (entries) {

                        var i;
                        for (i = 0; i < entries.length; i++) {
                            if (entries[i].isDirectory === true) {
                                // Recursive -- call back into this subdirectory
                                addFileEntry(entries[i]);
                            } else {
                                var ext = entries[i].name.split('.').pop();
                                if (ext === 'doc' || ext === 'docx' ||
                                    ext === 'rdf' || ext === 'pdf' || ext === 'txt' ||
                                    ext === 'odt') {

                                    fileList.push(entries[i]); // << replace with something useful
                                }
                                index++;
                            }
                        }
                    },
                    function (error) {
                        console.log('readEntries error: ' + error.code);
                        errorStr += '<p>readEntries error: ' + error.code + '</p>';
                    }
                );
            };
            var addError = function (error) {
                console.log('getDirectory error: ' + error.code);
                errorStr += '<p>getDirectory error: ' + error.code + ', ' + error.message + '</p>';
            };
            for (i = 0; i < localURLs.length; i++) {
                if (localURLs[i] === null || localURLs[i].length === 0) {
                    continue; // skip blank / non-existent paths for this platform
                }
                window.resolveLocalFileSystemURL(localURLs[i], addFileEntry, addError);
            }
            $scope.fileList = fileList;
            $scope.localFileError = errorStr;

The following is on the cordova config.xml file..

<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" />

Can you please let me know how to fix this issue. I can see files in the download and sdcard folders in android for API <=22 but not >=26

I have to deploy a release to production and this main functionality is broken. Also, I cannot use API 22 in the store,, It has to be >=26.

Is it possible to provide a quick work-a-round/patch or a timeline of a fix for this issue. please

Thanks

premtemp1 avatar Oct 02 '18 00:10 premtemp1

Did you fix the problem @premtemp1 before your release? If so, could you update us how?

janpio avatar Jun 07 '19 13:06 janpio

I have fixed this downgrading Android minAPI=22 and targetAPI=27 (before was minAPI=23 targetAPI=29 and not working)

sytolk avatar Sep 18 '20 16:09 sytolk

stale

Note that modern SDK targets can no longer read the directories of some external directories. Additionally files that you have permission to view will be shown in external storage.

breautek avatar Jan 25 '23 00:01 breautek