Android – Download and save images to SD card using Picasso

In my blog I always try to address pain points of developers, so does most of the naive developers face difficulty to download and save images for their respective Android apps into SD card. And they ended up writing more complicated logic and which may create other issues, for that reason only I am going to explain a simple and robust way to downloading and saving images in SD card using Picasso.


Picasso is a famous library from Square, used by developers for downloading images and displaying them but many do not know that it has capability of not only downloading but also saving those images as per individual’s requirement, let’s have a look on how one can achieve this.

Include Picasso into Gradle

First of all we need to include the library to the build.gradle file of the App module.

dependencies {
    //other libraries
    compile "com.squareup.picasso:picasso:2.4.0"

Use of Target

Picasso has an Interface called Target, you just need to create another class which implements this Interface and you can save the downloaded image bitmap to a file of your required location in SD Card. Here is a sample class for your reference. Once your class is ready you just need to call while downloading images.

import android.os.Environment;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

public class PhotoLoader implements Target {
    private final String name;
    private ImageView imageView;

    public PhotoLoader(String name, ImageView imageView) { = name;
        this.imageView = imageView;

    public void onPrepareLoad(Drawable arg0) {

    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom arg1) {
        File file = new File(Environment.getExternalStorageDirectory().getPath() + "/" + name);
        try {
            FileOutputStream ostream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 75, ostream);

        } catch (Exception e) {

    public void onBitmapFailed(Drawable arg0) {

Read about other libraries from Square –

 Downloading images

Now to download the image to display you need to call Picasso class which actually downloads the images –

String url = "";
String imageName = "trolltunga.jpg";
                    .into(new PhotoLoader(imageName , mImageView));

As you can see I am using PhotoLoader class which implements Target Interface.


So it is pretty easy to download and save images in SD card using Picasso, and another good part of using it is a very small library compare to other image downloading libraries available.

I hope this article will be helpful for you, so do not forget to subscribe and if you are already subscribed then share this post to you friends and colleagues so they can also take advantage.


Keep coding!!!

Leave a Reply

Your email address will not be published. Required fields are marked *