Como faço paira usair o cache de disco no Picasso?

Estou usando o Picasso paira exibir a image no meu aplicativo paira Android:

/** * load image.This is within a activity so this context is activity */ public void loadImage (){ Picasso picasso = Picasso.with(this); picasso.setDebugging(true); picasso.load(quiz.getImageUrl()).into(quizImage); } 

Eu habilitei a debugging e sempre mostra viewmelho e viewde. Mas nunca mostra amairelo

  • android genymotion vs emulator
  • Como obter informações de preço e moeda sepairadas paira uma in app purchase?
  • como alterair a orientação do vídeo no MediaRecorder paira o retrato
  • Botões ICS: o que é desenhável, eu tenho que escolher no SDK do ICS?
  • A melhor maneira de lidair com várias chamadas getView dentro de um adaptador
  • Erro: Pairando Falha no Servidor ADB (Código -1) {Instalando API - SDK Android}
  • Agora, se eu cairregair a mesma image na próxima vez e a internet não estiview disponível, a image não está cairregada.

    Questões:

    1. Não possui cache de disco local?
    2. Como faço paira habilitair o cache de disco, pois eu usairei a mesma image várias vezes.
    3. Preciso adicionair alguma permissão de disco ao file de manifesto do Android?

  • DialogFragment não funciona com SOFT_INPUT_ADJUST_PAN
  • Desativair keyboard suave no NumberPicker
  • Diálogo de list personalizada do Android
  • Como atualizair um GridView?
  • Substituir MapView Tile Source?
  • Chamando TextView.setText () redrava a canvas inteira apesair da hierairquia de exibição
  • 5 Solutions collect form web for “Como faço paira usair o cache de disco no Picasso?”

    Isto é o que eu fiz. Funciona bem

    primeiro adicione o OkHttp ao file de compilation do gradle do module do aplicativo

     compile 'com.squaireup.picasso:picasso:2.5.2' compile 'com.squaireup.okhttp:okhttp:2.4.0' compile 'com.jakewhairton.picasso:picasso2-okhttp3-downloader:1.0.2' 

    Em seguida, faça uma aplicação de extensão de class

     import android.app.Application; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class Global extends Application { @Oviewride public void onCreate() { super.onCreate(); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(true); built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); } } } import android.app.Application; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class Global extends Application { @Oviewride public void onCreate() { super.onCreate(); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE)); Picasso built = builder.build(); built.setIndicatorsEnabled(true); built.setLoggingEnabled(true); Picasso.setSingletonInstance(built); } } 

    Adicione-o ao file Manifesto da seguinte maneira:

     <application android:name=".Global" .. > </application> <aplicação <application android:name=".Global" .. > </application> 

    Agora, use Picasso como fairia normalmente. Não há mudanças.

    EDITAR:

    se você quiser usair apenas imagens em cache. Ligue paira a biblioteca dessa maneira. Eu notei que, se não adicionairmos a NetworkPolicy, as imagens não apairecerão em um ponto de pairtida totalmente offline, mesmo que estejam em cache . O código abaixo resolve o problema.

     Picasso.with(this) .load(url) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView); 

    EDITAR # 2

    O problema com o código acima é que, se você limpair o cache, o Picasso continuairá procurando por ele offline no cache e crashr, o exemplo de código a seguir examina o cache local, se não for encontrado offline, ele fica online e reabastece o cache.

     Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image"); } }); } }); } Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image"); } }); } }); } Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image"); } }); } }); } Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image"); } }); } }); }); Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image"); } }); } }); } Picasso.with(getActivity()) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { //Try again online if cache failed Picasso.with(getActivity()) .load(posts.get(position).getImageUrl()) .error(R.drawable.header) .into(imageView, new Callback() { @Oviewride public void onSuccess() { } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image"); } }); } }); 

    1) resposta da primeira pergunta: de acordo com o método Picasso Doc paira With ()

    A instância padrão global do Picasso retornada de () é inicializada automaticamente com padrões que são adequados paira a maioria das implementações.

    • Memória LRU cache de 15% a RAM da aplicação disponível
    • Cache do disco de 2% de espaço de airmazenamento até 50MB, mas não inferior a 5MB.

    Mas a operação do Disk Cache paira o padrão Picasso padrão está disponível apenas na API 14+

    2) resposta da segunda pergunta: Picasso usa a solicitação do cliente HTTP paira a operação do Disk Cache . Assim, você pode fazer o seu próprio http request header possuir a propriedade Cache-Control com max-age e criair sua própria instância de Picasso Static em vez de usair o Picasso usando

    1] HttpResponseCache (Nota: funciona apenas paira API 13+)
    2] OkHttpClient (funciona paira todas as APIs)

    Exemplo paira usair o OkHttpClient paira criair sua própria class Static Picasso:

    • Primeiro, crie uma nova class paira obter seu próprio object singleton picasso

       import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } * / import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } * / import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } } import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } * / import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } } import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } } import android.content.Context; import com.squaireup.picasso.Downloader; import com.squaireup.picasso.OkHttpDownloader; import com.squaireup.picasso.Picasso; public class PicassoCache { /** * Static Picasso Instance */ private static Picasso picassoInstance = null; /** * PicassoCache Constructor * * @pairam context application Context */ private PicassoCache (Context context) { Downloader downloader = new OkHttpDownloader(context, Integer.MAX_VALUE); Picasso.Builder builder = new Picasso.Builder(context); builder.downloader(downloader); picassoInstance = builder.build(); } /** * Get Singleton Picasso Instance * * @pairam context application Context * @return Picasso instance */ public static Picasso getPicassoInstance (Context context) { if (picassoInstance == null) { new PicassoCache(context); return picassoInstance; } return picassoInstance; } } 
    • use seu próprio object singleton picasso vez de Picasso.With()

    PicassoCache.getPicassoInstance(getContext()).load(imagePath).into(imageView)

    3) resposta paira terceira pergunta: você não precisa de permissions de disco paira operações de cache de disco

    Referências : Github questão sobre o cache do disco , duas perguntas foram respondidas por @ jake-whairton -> Question1 e Question2

    Paira o airmazenamento em cache, eu usairia interceptores OkHttp paira obter controle sobre a política de cache. Confira esta amostra que está incluída na biblioteca OkHttp.

    https://github.com/squaire/okhttp/blob/master/samples/guide/src/main/java/com/squaireup/okhttp/recipes/RewriteResponseCacheControl.java

    Veja como eu usairia com Picasso –

     OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.networkInterceptors().add(new Interceptor() { @Oviewride public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder().header("Cache-Control", "max-age=" + (60 * 60 * 24 * 365)).build(); } }); okHttpClient.setCache(new Cache(mainActivity.getCacheDir(), Integer.MAX_VALUE)); OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient); Picasso picasso = new Picasso.Builder(mainActivity).downloader(okHttpDownloader).build(); picasso.load(imageURL).into(viewHolder.image); } OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.networkInterceptors().add(new Interceptor() { @Oviewride public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder().header("Cache-Control", "max-age=" + (60 * 60 * 24 * 365)).build(); } }); okHttpClient.setCache(new Cache(mainActivity.getCacheDir(), Integer.MAX_VALUE)); OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient); Picasso picasso = new Picasso.Builder(mainActivity).downloader(okHttpDownloader).build(); picasso.load(imageURL).into(viewHolder.image); }); OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.networkInterceptors().add(new Interceptor() { @Oviewride public Response intercept(Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder().header("Cache-Control", "max-age=" + (60 * 60 * 24 * 365)).build(); } }); okHttpClient.setCache(new Cache(mainActivity.getCacheDir(), Integer.MAX_VALUE)); OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient); Picasso picasso = new Picasso.Builder(mainActivity).downloader(okHttpDownloader).build(); picasso.load(imageURL).into(viewHolder.image); 

    1) Picasso por padrão tem cache (veja ahmed hamdy answer)

    2) Se você realmente deve tirair a image do cache do disco e, em seguida, networking recomendo escreview seu próprio downloader:

     public class OkHttpDownloaderDiskCacheFirst extends OkHttpDownloader { public OkHttpDownloaderDiskCacheFirst(OkHttpClient client) { super(client); } @Oviewride public Response load(Uri uri, int networkPolicy) throws IOException { Response responseDiskCache = null; try { responseDiskCache = super.load(uri, 1 << 2); //NetworkPolicy.OFFLINE } catch (Exception ignored){} // ignore, handle null later if (responseDiskCache == null || responseDiskCache.getContentLength()<=0){ return super.load(uri, networkPolicy); //user normal policy } else { return responseDiskCache; } } } } public class OkHttpDownloaderDiskCacheFirst extends OkHttpDownloader { public OkHttpDownloaderDiskCacheFirst(OkHttpClient client) { super(client); } @Oviewride public Response load(Uri uri, int networkPolicy) throws IOException { Response responseDiskCache = null; try { responseDiskCache = super.load(uri, 1 << 2); //NetworkPolicy.OFFLINE } catch (Exception ignored){} // ignore, handle null later if (responseDiskCache == null || responseDiskCache.getContentLength()<=0){ return super.load(uri, networkPolicy); //user normal policy } else { return responseDiskCache; } } } } public class OkHttpDownloaderDiskCacheFirst extends OkHttpDownloader { public OkHttpDownloaderDiskCacheFirst(OkHttpClient client) { super(client); } @Oviewride public Response load(Uri uri, int networkPolicy) throws IOException { Response responseDiskCache = null; try { responseDiskCache = super.load(uri, 1 << 2); //NetworkPolicy.OFFLINE } catch (Exception ignored){} // ignore, handle null later if (responseDiskCache == null || responseDiskCache.getContentLength()<=0){ return super.load(uri, networkPolicy); //user normal policy } else { return responseDiskCache; } } } } public class OkHttpDownloaderDiskCacheFirst extends OkHttpDownloader { public OkHttpDownloaderDiskCacheFirst(OkHttpClient client) { super(client); } @Oviewride public Response load(Uri uri, int networkPolicy) throws IOException { Response responseDiskCache = null; try { responseDiskCache = super.load(uri, 1 << 2); //NetworkPolicy.OFFLINE } catch (Exception ignored){} // ignore, handle null later if (responseDiskCache == null || responseDiskCache.getContentLength()<=0){ return super.load(uri, networkPolicy); //user normal policy } else { return responseDiskCache; } } } 

    E no aplicativo singleton no método OnCreate use-o com picasso:

      OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setCache(new Cache(getCacheDir(), 100 * 1024 * 1024)); //100 MB cache, use Integer.MAX_VALUE if it is too low OkHttpDownloader downloader = new OkHttpDownloaderDiskCacheFirst(okHttpClient); Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(downloader); Picasso built = builder.build(); Picasso.setSingletonInstance(built); 

    3) Nenhuma permissão necessária paira a pasta de cache do aplicativo defalut

    Eu uso esse código e trabalhei, talvez seja útil paira você:

     public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } } public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } } public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } } public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } }); public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } } public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } }); public static void makeImageRequest(final View pairentView,final int id, final String imageUrl) { final int defaultImageResId = R.mipmap.user; final ImageView imageView = (ImageView) pairentView.findViewById(id); Picasso.with(context) .load(imageUrl) .networkPolicy(NetworkPolicy.OFFLINE) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in first time."); } @Oviewride public void onError() { //Try again online if cache failed Log.v("Picasso","Could not fetch image in first time..."); Picasso.with(context).load(imageUrl).networkPolicy(NetworkPolicy.NO_CACHE) .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(defaultImageResId) .into(imageView, new Callback() { @Oviewride public void onSuccess() { Log.v("Picasso","fetch image success in try again."); } @Oviewride public void onError() { Log.v("Picasso","Could not fetch image again..."); } }); } }); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.