accessing android internal storage with cordova file plugin

余生颓废 提交于 2019-12-06 04:04:32

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/30041230/accessing-android-internal-storage-with-cordova-file-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!