科尔多瓦:不能够复制使用Android的科尔多瓦文件 [英] Cordova: Not able to copy file on Android using Cordova

查看:166
本文介绍了科尔多瓦:不能够复制使用Android的科尔多瓦文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图设置下列权当不知怎的,我不断收到错误code 5。
我想要做的,采用的是Android拷贝从资产的现有文件到Android设备上的访问点,以便能够在其他应用共享(如电子邮件)。

下面是我的code例如:

  window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
    VAR storagefolder = cordova.file.dataDirectory;
    VAR storagefolderpointer;
    的console.log(存储文件夹:+ storagefolder);    //检查支持。
    如果(window.requestFileSystem){
        的console.log(文件系统beschikbaar);
        VAR getFSfail =功能(){
            的console.log(无法打开文件系统');
        };
        VAR getFSsuccess =功能(FS){            VAR getDIRsuccess =功能(DIR){
                    console.debug('得到DIRHANDLE');
                    cachedir = DIR;
                    fileurl = fs.root.fullPath +'/'+ storagefolder;
                    storagefolderpointer = DIR;
            };
            VAR getDIRfail =功能(){
                的console.log(无法打开目录);
            };            console.debug('得到fshandle');
            FS = FS;
            FS.root.getDirectory(storagefolder,{创建:真实,独家:假},getDIRsuccess,getDIRfail);
        };
        window.requestFileSystem(LocalFileSystem.PERSISTENT,0,getFSsuccess,getFSfail);        的setTimeout(函数(){            的console.log(目录beschikbaar);
            VAR SUC =功能(输入){
                VAR专家组=功能(){
                    的console.log(复制成功);
                };
                VAR缶=功能(){
                    的console.log(副本。NOT成功);
                };
                entry.copyTo(storagefolder,vcard.vcf,专家组,缶);
            };
            VAR辉=功能(E){
                的console.log(失败的GetFile:+ E code);
            };
            window.resolveLocalFileSystemURL(storagefolderpointer +WWW / visitekaart / vcard.vcf,SUC,FAI);        },1000);    }其他{
        的console.log(文件系统的。NOT不可用);
    }


解决方案

有使用cordovaFile插件呢?,你可以用一滴来读取文件的内容不是写在使用cordovaFile插件Android的SD卡一个新的

  $ cordovaFile.writeFile('应用程序数据/ file.txt的,一滴,0)。然后(功能(FileEntry的){
    //成功
},功能(错误){
    //呃
}

Somehow I keep getting an "error code 5" when trying to set the following right. What I want to do, is copy an existing file from the assets in android to an accessible spot on the android device to be able to share it across other apps (like mail).

Here is my code example:

    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    var storagefolder = cordova.file.dataDirectory;
    var storagefolderpointer;
    console.log("storage folder: " + storagefolder);

    // Check for support.
    if (window.requestFileSystem) {
        console.log("filesystem beschikbaar");
        var getFSfail = function () {
            console.log('Could not open filesystem');
        };
        var getFSsuccess = function(fs) {

            var getDIRsuccess = function (dir) {
                    console.debug('Got dirhandle');
                    cachedir = dir;
                    fileurl  = fs.root.fullPath + '/' + storagefolder;
                    storagefolderpointer = dir;
            };
            var getDIRfail = function () {
                console.log('Could not open directory');
            };

            console.debug('Got fshandle');
            FS = fs;
            FS.root.getDirectory(storagefolder, {create:true,exclusive:false}, getDIRsuccess, getDIRfail);
        };
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, getFSsuccess, getFSfail);

        setTimeout(function() {

            console.log("directory beschikbaar");
            var suc = function(entry){
                var goe = function(){
                    console.log("copy success");
                };
                var fou = function(){
                    console.log("copy NOT NOT success");
                };
                entry.copyTo(storagefolder, "vcard.vcf", goe, fou);
            };
            var fai = function(e){
                console.log("fail getFile: " + e.code);
            };
            window.resolveLocalFileSystemURL(storagefolderpointer + "www/visitekaart/vcard.vcf", suc, fai);

        }, 1000);

    } else {
        console.log("filesystem NOT NOT NOT available");
    }

解决方案

have you use cordovaFile plugin instead?,you can use blob to read the content of your files than write a new one on android sdcard using cordovaFile plugin

$cordovaFile.writeFile('appdata/file.txt', blob, 0).then(function(fileEntry) {
    //success
}, function(err) {
    //err
}

这篇关于科尔多瓦:不能够复制使用Android的科尔多瓦文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆