科尔多瓦/电话间隙文件未创建为什么

cordova / phonegap file is not created why?

本文关键字:文件 间隙 创建 为什么 电话间 电话      更新时间:2023-09-26

当我打开一个文件(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 );
        });

在之前测试以检查文件。

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