0

I got a question about android fresco library. Do you guys know how to get callback when file is saved in cache? Generally, we could get file from cache:

ImageRequest imageRequest= ImageRequest.fromUri(url);
CacheKey cacheKey= DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File file=((FileBinaryResource)resource).getFile();

However, if I put this in onCreate() function, it will crash since the file was not in the cache yet. Do you guys know how I got get a callback when the fresco finish saving it? Is it DataSubscriber? Could you guys provide an example? I read the documentation but I couldn't figure out.

Thanks.

Shumin
  • 991
  • 2
  • 13
  • 22

1 Answers1

0

I am part of the Fresco team and may be able to help. Please see our documentation on how to properly get the encoded image bytes. There is a code example of how to get an InputStream of the encoded image (which is what is being stored in cache). You can then use those bytes directly, or if you need a File in order to pass it somewhere else, you should create your own file and store the returned bytes in it. There is no other safe way to deal with cached images because you have no guarantees that Fresco will not evict (delete) the cached file at any time.

plamenko
  • 1,068
  • 1
  • 8
  • 10
  • As we know, fresco can't resize gif or png and such stuff.If i wanna resize it, i have to compress it my self.After getting a compressed bitmap, i don't know how to load it by fresco.Could you give me some advise? – Allen Vork Apr 29 '16 at 02:08