0

Why is my image not getting cached while using Picasso? When i switch off the internet, the same image doesnt load. I am using this to get the image

final Bitmap m = getImageLoader(context, user).load(uri).get();

where getImageLoader() is

public Picasso getImageLoader(Context ctx,final User user) {
        Picasso.Builder builder = new Picasso.Builder(ctx);

        builder.downloader(new OkHttpDownloader(ctx) {
            @Override
            protected HttpURLConnection openConnection(Uri uri) throws IOException {
                HttpURLConnection connection = super.openConnection(uri);

                connection.setRequestProperty("X-User",user.getUsername());
                connection.setRequestProperty("X-Token",user.getToken());

                return connection;
            }
        });
        return builder.build();
    }

Does it has something to do with the HTTP headers. Here is my other question regarding this.

Community
  • 1
  • 1
Diffy
  • 2,339
  • 3
  • 25
  • 47
  • I also want to know about caching using Picasso lib. I searched the web and found about okhttp . But I could not go beyond that :( – Paritosh Aug 09 '14 at 13:42

1 Answers1

0

I believe the only way to achieve this is to use transform().

Picasso.with(context).load(url).transform(new Transformation() {
        @Override
        public Bitmap transform(Bitmap source) {
            /*grab your Bitmap HERE!!*/
            //e.g. mBitmap = source;
            return source;
        }

        @Override
        public String key() {
            return "";
        }
    }).into(new ImageView(context));

Above code is just an example. You can always change .into(new ImageView(context)) with any ImageView, or use Uri instead of url.

Harry
  • 568
  • 1
  • 5
  • 20