简体   繁体   English

某些网址中的图片未加载到毕加索中

[英]Image from certain Url is not load in picasso

I load image from URL using picasso first time on line, After then use from cache. 我第一次使用picasso从URL加载图像,然后使用缓存。 Any URL from web is load in imageview on line or off line. 来自web的任何URL都在线上或离线加载到imageview But my server image URL is load image in on line not in off line. 但我的服务器图像URL是在线加载图像而非离线。 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 Web url在线或离线加载: URL

My server url load image only in online: URL 我的服务器url仅在online: URL中加载图片

I show in cache directory and found that image of my server URL is not cached. 我在缓存目录中显示,发现我的服务器URL的图像没有缓存。 Any have idea about that. 任何人都有这个想法。

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. 顺便说一下这个很老,但你可以使用Glide来获得更好的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM