簡體   English   中英

Phonegap Cordova刪除文件(android)

[英]Phonegap Cordova Delete File (android)

直升機..

我是手機新手......

我有一個問題,刪除android phonegap 3.4中的文件

console.log(photo);    

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
  function onFileSystemSuccess(fileSystem) {
    fileSystem.root.getFile(
      photo, {create: false},
      function gotFileEntry(fileEntry) {
        fileEntry.remove();
      },
      onError);
  },
  onError);

記錄結果

04-24 16:29:54.234:I / Web Console(16213):file:///storage/sdcard0/DCIM/Camera/1398331773136.jpg

04-24 16:49:01.989:W / System.err(18864):org.apache.cordova.file.EncodingException:此路徑中包含無效的“:”。

04-24 16:49:01.994:W / System.err(18864):at org.apache.cordova.file.LocalFilesystem.getFileForLocalURL(LocalFilesystem.java:159)

04-24 16:49:01.994:W / System.err(18864):at org.apache.cordova.file.FileUtils.getFile(FileUtils.java:698)

04-24 16:49:03.664:I / Web Console(18864):5

搜索之后,我在doc中得到了這個(錯誤代碼和含義列表)

5 = ENCODING_ERR

文件路徑是錯誤的以及如何在sdcard中獲取文件的有效路徑?

謝謝

我認為你的問題在於你調用回調函數的方式。 這段代碼對我有用:

console.log("remove file");
var relativeFilePath = "MyDir/file_name.png";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
    fileSystem.root.getFile(relativeFilePath, {create:false}, function(fileEntry){
        fileEntry.remove(function(file){
            console.log("File removed!");
        },function(){
            console.log("error deleting the file " + error.code);
            });
        },function(){
            console.log("file does not exist");
        });
    },function(evt){
        console.log(evt.target.error.code);
});

訪問以file://開頭的絕對路徑的最簡單方法是使用window.resolveLocalFileSystemURL()

var url = "file:///storage/emulated/0/Android/data/myPackageName/cache/1461244585881.jpg";

window.resolveLocalFileSystemURL(url, function(file) {
        file.remove(function(){
          console.log(url + " deleted");
        },onError);
      }, onError);

其他有用的鏈接:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM