You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2021/04/22 13:29:50 UTC

[GitHub] [cordova-plugin-file] joshuaokpako commented on issue #426: Storage updates in Android 11

joshuaokpako commented on issue #426:
URL: https://github.com/apache/cordova-plugin-file/issues/426#issuecomment-824842912


   I am using ionic 4 and I faced the same issue so I tried the ionic 4 version of resolveDirectoryUrl(cordova.file.externalRootDirectory, function (dirEntry) {)) and on success function I used dirEntry.getDirectory ('Download'... and I can create folders and save files to the Download folders on android 11 without adding android:requestLegacyExternalStorage="true". Here is the code for ionic 4. I have also tried to convert it to the normal web version.
   ```
   createDirectory(rootDir) {
       return new Promise((res, rej) => {
         this.file.resolveDirectoryUrl(rootDir).then((rootDirEntry)=>{
           
           rootDirEntry.getDirectory('Download', { create: false, exclusive:false},  (dirEntry) =>{
             dirEntry.getDirectory('updates', { create: true, exclusive:false}, (subDirEntry) =>{
               this.updateDir = subDirEntry;
               this.appDir = dirEntry;
               res(this.updateDir)
             }, (err)=> {
               this.onErrorGetDir(rootDir+'Download/','updates');
               rej(err)
             })
           }, (err)=> {
             this.onErrorGetDir(rootDir,'Download')
             rej(err)
           })
         })
         
       })
     }
   ```
   and the normal web version. Note that I have only tested the ionic 4 version of this code. 
   ```
   function createDirectory(rootDir /*cordova.file.externalRootDirectory*/) {
       window.resolveDirectoryURL(rootDir, function (rootDirEntry) {
         dirEntry.getDirectory('Download', { create: false, exclusive:false}, function (dirEntry) {
           dirEntry.getDirectory('updates', { create: true, exclusive:false}, function (subDirEntry) {
               /* delete a file or donwload a file using cordova-plugin-advanced-http.
                   I tested mine using cordova-plugin-advanced-http to download a file to this folder */
               createFile(subDirEntry, "fileInNewSubDir.txt");
   
           }, onErrorGetDir);
         }, onErrorGetDir);
       })
     }
   ```
   This doesn't allow you to write or read from the root directory but works with the download directory and probably other sub directories in the root directory.
   You will need READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org