【问题标题】:Cordova File api : getFile issue in androidCordova File api:android中的getFile问题
【发布时间】:2014-11-12 14:08:24
【问题描述】:

环境:安卓

在应用程序中,我在"/data/data/com.my.app/changes/123456789/123456789.json" 位置创建了一个文件 我已经使用自定义cordova android插件交叉检查了该文件是否存在。

当尝试使用如下所示的 cordova File api 访问此文件时。 api 根本无法提供 1000 个代码。

var path = "/changes/123456789/123456789.json"
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
                    function(fileSystem){
                        console.log('in got FS');
                        fileSystem.root.getFile(path,{create:true, exclusive: false},
                                function(fileEntry){
                                    console.log('gotFileEntry');
                                },
                                function(err){
                                    console.log('gotFileEntry fail');
                                    console.log('err.code');
                                    console.log(err.code);

                                    }
                                );

                    }, 
                    function(){
                        console.log('fail');
                        }
                    );

我收到一个错误代码为“1000”,我认为这是“找不到文件”。

根据新的插件文档,文件的路径应该是相对于文件系统根目录的。 我认为问题在于我传递文件路径的方式。

在 iOS 设备上测试时也是如此,问题仅在于 ANDROID。

请让我知道我到底哪里出错了。因为我完全卡住了。 非常感谢任何帮助。

提前致谢。

【问题讨论】:

  • 错误 1000 实际上是一个未知错误。

标签: android cordova cordova-plugins cordova-3.5


【解决方案1】:

您好,经过大量挖掘 Cordova file api 并在 post 的帮助下,能够访问 ANDROID 中的文件。

二手

window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir) {
    console.log("got main dir",dir);
    dir.getFile("log.txt", {create:true}, function(file) {
        console.log("got the file", file);

    });
});

在 Android 中获取文件条目。这也适用于 iOS。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 2018-04-10
    相关资源
    最近更新 更多