cordova / phonegap文件是不是为什么创建的?

时间:2016-02-25 08:57:02

标签: javascript android cordova phonegap-plugins

当我打开文件(cordova.plugins.fileOpener2.open .......)时,手机会通知您找不到该文件,但控制台中没有错误。有什么问题?

       window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
            //console.log(fileSystem.name);
            //console.log(fileSystem.root.name);
            //console.log(fileSystem.root.fullPath);
            fileSystem.root.getFile("test.txt", {create: true}, function(entry) {
                var fileEntry = entry;
               // console.log(entry.fullPath);
                entry.createWriter(function(writer) {
                    writer.onwrite = function(evt) {
                        console.log("some sample text");
                    };
                    writer.write("sample text");
                    writer.onwriteend = function(evt) {
                        $scope.pathFile = writer.localURL;
                        console.log($scope.pathFile);
                        cordova.plugins.fileOpener2.open(
                            $scope.pathFile,
                            'text',
                            {
                                error : function(e) {
                                    console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
                                },
                                success : function () {
                                    console.log('file opened successfully');
                                }
                            }
                        );
                    };
                }, function(error) {
                    console.log(error);
                });
            }, function(error){
                console.log(error);
            });
        },
        function(event){
            console.log( event.target.error.code );
        });

1 个答案:

答案 0 :(得分:0)

在检查文件之前对此进行测试。

    function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
    }

    function gotFS(fileSystem) {
        fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
    }

    function gotFileEntry(fileEntry) {
        console.log("gotFileEntry");
    }

    function fail(evt) {
        console.log("Error : "+evt.code);
    }