Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing android internal storage with cordova file plugin

I'm trying to make an android app that, so far, is using the native voice recorder to record audio.

The path for that is the Sounds file in /storage/emulated/0/Sounds

Now the app is using the File Transfer cordova plugin. The root for that is /data/data/thisAppDirectory and requestFileSystem is using this as the path.

Is it possible to go up a directory with the file system to get to the sounds folder?

like image 445
realisation Avatar asked May 04 '15 22:05

realisation


1 Answers

Yes here we go! You have to utilize cordova file-transfer plugin, like so:

 window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs){
                    fs.root.getFile("'"+audioData[0].name+"'", {create: true, exclusive: false},
                      function(entry){
                        var fileTransfer = new FileTransfer();
                        fileTransfer.download(
                                "file:///storage/emulated/0/Sounds/" + audioData[0].name, // the filesystem uri you mentioned                  
                                "cdvfile://localhost/temporary/" + audioData[0].name,
                                function(entry) {
                                    // do what you want with the entry here
                                    console.log("download complete: " + entry.fullPath);
                                    window.requestFileSystem(LocalFileSystem.TEMPORARY, 1000000000, gotFS, fail);
                                },
                                function(error) {
                                    console.log("error source " + error.source);
                                    console.log("error target " + error.target);
                                    console.log("error code " + error.code + "Cheeeese");
                                },
                                false,
                                null
                        );
                    }, function(){
                        alert("file create error");
                    });
                }, null);
like image 133
realisation Avatar answered Sep 26 '22 00:09

realisation