删除phonegap中的缓存图像

时间:2013-07-16 07:38:12

标签: android cordova caching camera delete-file

我目前正在使用Phonegap技术开发Android应用程序,为您提供信息,我的应用程序概念如下

  1. 捕获图像(默认情况下,Phonegap会在本地存储缓存图像:即图像路径为(file://androidappnames/cache/21323213.jpg)

  2. 检索图像

  3. 对图像进行一些处理。
  4. 问题是,如何删除缓存图像?

2 个答案:

答案 0 :(得分:1)

此代码不会删除缓存,但会阻止使用缓存数据。

var success = function(){};
var error = function(){};


navigator.camera.getPicture(success, error,
    {
        quality: 99,
        destinationType: Camera.DestinationType.DATA_URL,
        sourceType: Camera.PictureSourceType.CAMERA,
        encodingType: Camera.EncodingType.PNG,
        correctOrientation: true,
        allowEdit: true
    }
);  

destinationType设为Camera.DestinationType.DATA_URL而不是Camera.DestinationType.FILE_URI

在此处阅读更多内容:http://docs.phonegap.com/en/2.9.0rc1/cordova_camera_camera.md.html

答案 1 :(得分:1)

出于删除目的,我们可以使用如下文件API:

function removeAllCache(){
window.resolveLocalFileSystemURL(cordova.file.externalCacheDirectory, gotDirRemove, function(error){});

}

function gotDirRemove(entry){
var directoryReader = entry.createReader();
directoryReader.readEntries(function(entries) {
    var i;
    for (i = 0; i < entries.length; i++) {
        entries[i].remove(function(file){
        },function(error){
            });
    }
},function(){});
}
相关问题