Image from certain Url is not load in picasso

最后都变了- 提交于 2019-12-11 07:29:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/47768373/image-from-certain-url-is-not-load-in-picasso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!