1

I load image from URL using picasso first time on line, After then use from cache. Any URL from web is load in imageview on line or off line. But my server image URL is load image in on line not in off line. I use below code from image load.

 Picasso.with(mContext)
            .load(urlProfile)
            .networkPolicy(NetworkPolicy.OFFLINE)
            .placeholder(R.drawable.ic_place_holder)
            .into(imageView, new Callback() {
                @Override
                public void onSuccess() {

                }

                @Override
                public void onError() {
                    Picasso.with(mContext)
                            .load(urlProfile)
                            .placeholder(R.drawable.ic_place_holder)
                            .into(imageView);
                }
            }); 

Web url load in online or offline both : URL

My server url load image only in online: URL

I show in cache directory and found that image of my server URL is not cached. Any have idea about that.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
kinjal patel
  • 585
  • 2
  • 4
  • 12

1 Answers1

3

Hi below is my solutions and it's working perfectlly.

Picasso.with(mContext)
                .load(Uri.parse(urlProfile))
                .networkPolicy(NetworkPolicy.OFFLINE)
                .into(iv_view, new Callback() {
                    @Override
                    public void onSuccess() {
                        // if you are showing progress then handle it on here
                    }

                    @Override
                    public void onError() {
                        // Try again online if cache failed and download using internet                          
                        new Picasso.Builder(mContext)
                                .downloader(new OkHttpDownloader(mContext, Integer.MAX_VALUE))
                                .build()
                                .load(Uri.parse(urlProfile))
                                .placeholder(R.mipmap.ic_launcher)
                                .into(iv_view);
                    }
                });

Hope this helps you..

By the way this is very old but you can use Glide for better performance.

Jyubin Patel
  • 1,373
  • 7
  • 17