使用cordova文件插件访问android内部存储 [英] accessing android internal storage with cordova file plugin

查看:268
本文介绍了使用cordova文件插件访问android内部存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我正在尝试制作一个使用本地录音机录制音频的android应用.

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

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

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

现在,该应用程序正在使用File Transfer cordova插件.根目录为/data/data/thisAppDirectory,requestFileSystem将此目录用作路径.

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?

推荐答案

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

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

这篇关于使用cordova文件插件访问android内部存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆