How can I save an image to sd card?
How can I save an image to sd card? What to do with cacheFile?
public void DownloadClicked(String url){
Uri uri = Uri.parse(url);
ImageRequest downloadRequest = ImageRequest.fromUri(uri);
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(downloadRequest);
if (ImagePipelineFactory.getInstance().getMainDiskStorageCache().hasKey(cacheKey)) {
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File cacheFile = ((FileBinaryResource) resource).getFile();
try{
FileInputStream fis = new FileInputStream(cacheFile);
ImageFormat imageFormat = ImageFormatChecker.getImageFormat(fis);
switch (imageFormat) {
case GIF:
//copy cacheFile to sdcard
break;
}
}catch (Exception e){
e.printStackTrace();
}
}
}
Please read our documentation Using the Image Pipeline Directly and DataSources and DataSubscribers.
Do not access the disk cache directly, but submit the image request and subscribe your data subscriber as explained in the "get encoded image" example in the documentation.
what is work for executor there? while simply downloading images from bitmap subscriber
I found they mention it in https://github.com/facebook/fresco/issues/265. However, the doc has not get updated. I found it is runnable with this: new Executor() { @Override public void execute(Runnable command) { command.run(); } }
How do you retrieve the GIF file from the subscriber?