Downloading Images With Picasso Android Disck
I'm using the Picasso library to download and display images in a listview, I'm using the following code: Picasso.with(mContext).load(listItem.getMainPhoto()).into(holder.image)
Solution 1:
i know this is a old question but maybe someone can find this useful.
you can download an image with picasso using a target:
Picasso.with(mContext)
.load(listItem.getMainPhoto())
.into(target);
privateTarget target = newTarget() {
@OverridepublicvoidonBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
newThread(newRunnable() {
@Overridepublicvoidrun() {
File file = newFile(Environment.getExternalStorageDirectory().getPath() +"/imagename.jpg");
try
{
file.createNewFile();
FileOutputStream ostream = newFileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 75, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}).start();
}
@OverridepublicvoidonBitmapFailed(Drawable errorDrawable) {
}
@OverridepublicvoidonPrepareLoad(Drawable placeHolderDrawable) {
if (placeHolderDrawable != null) {
}
}
};
To clean the cache you can add this class to the picasso package:
package com.squareup.picasso;
publicclassPicassoTools {
publicstaticvoidclearCache(Picasso p) {
p.cache.clear();
}
}
Post a Comment for "Downloading Images With Picasso Android Disck"