Cordova文件传输崩溃的应用程序

时间:2014-04-07 06:21:03

标签: android cordova file-transfer cordova-plugins

我正在开发基于Android的cordova 3.4.0,我的目标是下载一个文件并打开它。显然下载文件后,我很快就停留在下载位上,因为它是墓碑。

已安装插件,权限为:

<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

我还有一个应用程序行:

android:largeHeap="true"

代码是:

    downloadFile: {

    run: function(uri, fileName, folderName) {

        var that = this;

        filePath = "";

        that.getFilesystem(
            function(fileSystem) {
                console.log("gotFS");

                if (APP.isAndroid()) {
                    that.getFolder(
                        fileSystem,
                        folderName,
                        function(folder) {
                            filePath = folder.toURL() + "\/" + fileName;
                            console.log("FILE PATH :::: " + filePath);
                            that.transferFile(uri, filePath);
                        }, function() {
                            console.log("failed to get folder");
                        }
                    );
                }
                else {
                    filePath = fileSystem.root.fullPath + "\/" + fileName;
                    that.transferFile(uri, filePath);
                }
            },
            function() {
                console.log("failed to get filesystem");
            }
        );
    },

    getFilesystem:function (success, fail) {
        window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, fail);
    },

    getFolder: function (fileSystem, folderName, success, fail) {
        fileSystem.root.getDirectory(folderName, {create: true, exclusive: false}, success, fail)
    },


    transferFile: function (uri, filePath) {
        var transfer = new FileTransfer();
        console.log("Trying to DL  : : " + encodeURI(uri) + " to " + filePath);
        /** **/
        transfer.download(
            encodeURI(uri),
            filePath,
            function (entry) {
                console.log("TRYING TO OPEN FILE ::: " + entry.toURL());
            },
            function (error) {
                console.log("download error source " + error.source);
                console.log("download error target " + error.target);
                console.log("upload error code" + error.code);
            }
        );
    }
},

.....

this.downloadFile.run(url, "file_name.pdf", "pdfs");

这似乎下载了文件,然后像这样的墓碑,偶尔到达成功回调。 :

    I/chromium(26125): [INFO:CONSOLE(388)] "TRYING TO OPEN FILE ::: cdvfile://localhost/persistent/fileName", source: file:///android_asset/www/app/env.js (388)
F/libc    (26125): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 26203 (GAThread)
I/DEBUG   (  269): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  269): Build fingerprint: 'motorola/falcon_asia_ds/falcon_umtsds:4.4.2/KXB20.25-1.31/14:user/release-keys'
I/DEBUG   (  269): Revision: 'p3c0'
I/DEBUG   (  269): pid: 26125, tid: 26203, name: GAThread  >>> nz.co.forsythbarr.mobileapp <<<
I/DEBUG   (  269): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
D/WifiStateMachine( 1010): handleMessage: E msg.what=151572
D/WifiStateMachine( 1010): processMsg: ConnectedState
D/WifiStateMachine( 1010): processMsg: L2ConnectedState
I/DEBUG   (  269):     r0 00000000  r1 00000000  r2 625ca245  r3 00000028
I/DEBUG   (  269):     r4 00000008  r5 625ca246  r6 00000000  r7 ffffffff
I/DEBUG   (  269):     r8 00000001  r9 40b59130  sl 00000028  fp 625ca245
I/DEBUG   (  269):     ip 6402fb34  sp 64a39990  lr 64024105  pc 40b440f6  cpsr 600f0030
I/DEBUG   (  269):     d0  0000000000000000  d1  0000000000000000
I/DEBUG   (  269):     d2  0000000000000000  d3  0000000000000000
I/DEBUG   (  269):     d4  3268053561342f79  d5  796470730830312d
I/DEBUG   (  269):     d6  64707306312e332f  d7  7074746808332f79
I/DEBUG   (  269):     d8  0000000000000000  d9  0000000000000000
I/DEBUG   (  269):     d10 0000000000000000  d11 0000000000000000
I/DEBUG   (  269):     d12 0000000000000000  d13 0000000000000000
I/DEBUG   (  269):     d14 0000000000000000  d15 0000000000000000

.....

对于如何修复任何想法表示赞赏。

1 个答案:

答案 0 :(得分:0)

另一个原因可能是您使用的CrossWalk(替代浏览器插件)具有不同的Cookie API,FileTransfer插件不知道。修复https://github.com/gaochun/cordova-plugin-file-transfer/commit/0063249e279b99a0feb4601650fc3a4c9e8a8ed2?diff=split