【问题标题】:accessing android internal storage with cordova file plugin使用cordova文件插件访问android内部存储
【发布时间】:2015-05-04 22:41:50
【问题描述】:

我正在尝试制作一个 Android 应用程序,到目前为止,它正在使用本机录音机来录制音频。

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

现在该应用正在使用 File Transfer cordova 插件。它的根是 /data/data/thisAppDirectory 并且 requestFileSystem 使用它作为路径。

是否可以通过文件系统上一个目录进入声音文件夹?

【问题讨论】:

  • 如果您使用github.com/apache/cordova-plugin-file-transfer,您可以指定文件URL 用于上传/下载
  • 是的,但这会超出应用程序的根目录并被禁止吗?在接下来的几个小时内尝试一下。
  • 问题还在于我们没有使用普通的 http 服务器——我们使用的是 parse.com 数据库

标签: android cordova phonegap-plugins cordova-plugins


【解决方案1】:

是的,我们开始!您必须使用 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-25
    • 2016-07-27
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    • 2014-04-07
    相关资源
    最近更新 更多