2015-09-11 21 views
6

Wciąż próbuję uzyskać "kod błędu 5", próbując ustawić następujące prawo. Co chcę zrobić, to skopiować istniejący plik z zasobów w Androidzie do dostępnego miejsca na urządzeniu z Androidem, aby móc udostępnić je innym aplikacjom (takim jak poczta).Cordova: Nie można skopiować pliku na Androida za pomocą Cordova

Oto mój przykładowy kod:

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"); 
    } 
+2

Jest związany z [ten numer] (https://github.com/driftyco/ng-cordova/issues/506)? Zobacz 10. komentarz – lifeisfoo

+0

Czy próbowałeś korzystać z Filechooser? https://github.com/MaginSoft/MFileChooser –

+1

Błąd jest "ENCODING_ERR", jak w dokumentach https://github.com/apache/cordova-plugin-file, proszę podać go w pytaniu, które może być istotne. –

Odpowiedz

3

mieć użyć wtyczki cordovaFile zamiast tego można użyć blob do zapoznania się z zawartością plików niż pisać nowe na Androidzie sdcard użyciu cordovaFile wtyczki

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