Load images from disk cache with Picasso if offline

You can use this code by this strategy Picasso will look for images in cache and if it failed only then image will be downloaded over network.

 Picasso.with(context)
                    .load(Uri.parse(getItem(position).getStoryBigThumbUrl()))
                    .networkPolicy(NetworkPolicy.OFFLINE)
                    .into(holder.storyBigThumb, new Callback() {
                        @Override
                        public void onSuccess() {

                        }

                        @Override
                        public void onError() {
                            // Try again online if cache failed
                            Picasso.with(context)
                                    .load(Uri.parse(getItem(position)
                                            .getStoryBigThumbUrl()))
                            .placeholder(R.drawable.user_placeholder)
                            .error(R.drawable.user_placeholder_error)
                                    .into(holder.storyBigThumb);
                        }
                    });

Leave a Comment