fragatak edited a comment on issue #239:
URL: 
https://github.com/apache/cordova-plugin-file/issues/239#issuecomment-681093460


   This is the code that is used with the app first starts up to check 
permission.
   
   `function androidPermissions()
   {
       let permissions = cordova.plugins.permissions;
       let list = [
           permissions.WRITE_EXTERNAL_STORAGE,
           permissions.READ_EXTERNAL_STORAGE
       ];
   
       function error() {
           console.warn('External Read or Write permission is not turned on');
       }
   
       permissions.checkPermission(list, function (status) {
           if (!status.hasPermission) {
               permissions.requestPermissions(
               list,
               function(status) {
                   if (!status.hasPermission) error();
               },
               error
               );
           }
       }, null);
   }
   
   document.addEventListener("deviceready", androidPermissions, null);`
   
   
   and to read
   
   `function Fail(evt)
           {
               console.log(evt.target.error.code);
           }
   
           function error(e)
           {
               console.error("error in " + e);
           }
   
           function readConfig(entry)
           {
               entry.file((file) =>
               {
                   var reader = new FileReader();
   
                   reader.onloadend = () =>
                   {
                       // do whatever you need to do for reading the file.
                   };
   
                   reader.readAsText(file);
   
               }, () =>
               {
                   console.error("error loading config file.")
               });
           }
   
           let cordova = window.cordova || null;
           if (cordova)
           {
               document.addEventListener("deviceready", () =>
               {
                   window.requestFileSystem(1, 0, null, Fail);
                   window.resolveLocalFileSystemURL('file:///sdcard/{whatever 
file here]', readConfig.bind(this), error);
               });
           }`


----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to