来自特定网址的图片未加载到毕加索中 [英] Image from certain Url is not load in picasso

查看:55
本文介绍了来自特定网址的图片未加载到毕加索中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用picasso从URL加载图像,然后从缓存中使用.来自网络的任何URL都在线或离线加载到imageview中.但是我的服务器图像URL是在线加载而不是离线加载图像.我使用下面的图片加载代码.

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

我的服务器url只能在线加载图像: URL

My server url load image only in online: URL

我在缓存目录中显示,但发现未缓存服务器URL的图像.任何人对此都有想法.

I show in cache directory and found that image of my server URL is not cached. 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);
                    }
                });

希望这对您有所帮助.

这种方式已经很老了,但是您可以使用Glide以获得更好的性能.

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

这篇关于来自特定网址的图片未加载到毕加索中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆