微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用cordova文件插件访问android内部存储

我正在尝试创建一个Android应用程序,到目前为止,使用本机录音机录制音频.

其路径是/ storage / emulated / 0 / Sounds中的Sounds文件

现在该应用程序正在使用File Transfer cordova插件.它的根是/ data / data / thisAppDirectory,requestFileSystem使用它作为路径.

是否可以使用文件系统上一个目录来访问声音文件夹?

解决方法:

是的,我们走吧!您必须使用cordova文件传输插件,如下所示:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐