Android display images when offline once downloaded using fresco -
i want fresco download , save images sd-card when connected internet. later when offline , if cache cleared, still need fresco show saved images. possible? if yes, how?
simply saving images disk cache doesnt seem work when cache cleared.
fresco caches images you. if offline, images should still displayed. should not need anything.
however, when cache cleared (e.g. when user presses button or when device space low), images deleted cache - desired behavior should not changed.
there 2 options: save selected items, move cache
save selected items
if want persist selected images (e.g. "save" button), can encoded image , save somewhere on device. should not images since on disk 2 times , clearing cache / uninstalling app leave 1 copy on device.
something work:
datasource<closeablereference<pooledbytebuffer>> datasource = fresco.getimagepipeline().fetchencodedimage(imagerequest, callercontext); datasource.subscribe(new basedatasubscriber<closeablereference<pooledbytebuffer>>() { @override protected void onnewresultimpl(datasource<closeablereference<pooledbytebuffer>> datasource) { closeablereference<pooledbytebuffer> encodedimage = datasource.getresult(); if (encodedimage != null) { try { // save encoded image in pooledbytebuffer } { closeablereference.closesafely(encodedimage); } } } @override protected void onfailureimpl(datasource<closeablereference<pooledbytebuffer>> datasource) { // went wrong } }, executorservice);
}
more information on how use pipeline encoded image: http://frescolib.org/docs/using-image-pipeline.html
move cache
keep in mind persist cache when moved external directory, careful since leave files when app uninstalled.
fresco allows supply custom diskcacheconfig
, can create new diskcacheconfig.builder
, call setbasedirectorypath(file)
change path different folder (e.g. 1 on sd card) , can change directory name setbasedirectoryname(string)
more information on how fresco caching: http://frescolib.org/docs/caching.html
Comments
Post a Comment