在PhoneGap中删除缓存图像

3

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

  1. 拍摄照片(默认情况下,Phonegap将在本地存储缓存图像:即图像路径为(file://androidappnames/cache/21323213.jpg)

  2. 检索图像

  3. 对图像进行一些处理。

问题是,如何删除缓存的图像?


我有同样的问题。 - fiberOptics
2个回答

2
为了删除文件,我们可以使用如下的文件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(){});
}

嗨,只需添加removeAllCache();以调用该函数。 - pancy1

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接