Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fresco add Bitmap to Cache programmatically

I am uploading an image to my server and once uploaded my server responds with the new URI for it (can be the same URL as the old one), I want to remove the old cached image and insert the new one for the new URI.

I try to accomplish this by doing:

// Retrofit2 onResponse

String newImageUri = response.body().getUri();
String oldImageUri = Preferences.getUser().getImageUrl();   

// Remove old image from cache
Fresco.getImagePipeline().evictFromCache(Uri.parse(oldImageUri));               
Fresco.getImagePipeline().evictFromDiskCache(Uri.parse(oldImageUri));
Fresco.getImagePipeline().evictFromMemoryCache(Uri.parse(oldImageUri));
Fresco.getImagePipelineFactory().getMainFileCache().remove(new SimpleCacheKey(oldImageUri));

// Insert new image at new URI
try {
    Fresco.getImagePipelineFactory().getMainFileCache().insert(new SimpleCacheKey(newImageUri), new WriterCallback() {
        @Override
        public void write(OutputStream os) throws IOException {
            os.write(imageData); // byte[] or the new Bitmap
        }
    });
}
catch (Exception e) {
    e.printStackTrace();
}
uriProfileImage.setImageURI(newImageUri);

There are no exceptions but I still only see the old image.

like image 829
Arbitur Avatar asked Jun 05 '17 10:06

Arbitur


1 Answers

I solved it, it was an error with the Uri format for the new Uri...

like image 176
Arbitur Avatar answered Oct 20 '22 13:10

Arbitur