You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi , I'm using your wonderful library but i have a problem with it , the problem is i want to download a picture from a URL and save it to the storage and i'm using this code
Picasso.with(mContext)
.load("http://apod.nasa.gov/apod/image/1602/IMG_0193PorterAstroH.jpg")
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Log.d(TAG, "onBitmapLoaded is launched");
try {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/Image Capture");
if (!myDir.exists()) {
myDir.mkdirs();
}
String name = new Date().toString() + ".jpg";
myDir = new File(myDir, name);
FileOutputStream out = new FileOutputStream(myDir);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch(Exception e){
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.d(MainActivity.TAG, "Failed :(((" );
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
});
inside a button and when i press the button i see that its using the network to download the picture but as you see my loges don't show anything to me after the Target() Interface .
Sometimes it creates the folder and downloads the picture to my storage but usually it doesn't.
The text was updated successfully, but these errors were encountered:
I don't think Picasso is to be used as a download library. If you are not displaying the "bitmap" why don't you just stream the bytes from the URL to your file.?
Calling new Target will cause the target to be garbage collected immediately (and thus the code never run) since Picasso keeps a weak reference. Put your target in a field or somewhere else where a strong reference can be kept to prevent this and allow the code to work.
Other than that, this is a dupe of #506 which we just haven't gotten around to yet.
Hi , I'm using your wonderful library but i have a problem with it , the problem is i want to download a picture from a URL and save it to the storage and i'm using this code
inside a button and when i press the button i see that its using the network to download the picture but as you see my loges don't show anything to me after the Target() Interface .
Sometimes it creates the folder and downloads the picture to my storage but usually it doesn't.
The text was updated successfully, but these errors were encountered: