2017-10-16 58 views
2

我有以下代碼,如預定裝載圖像脫機其不列入。它在線運行良好,但我也需要離線加載圖像。我已經授予了編寫外部存儲的權限。任何想法都會非常有幫助。畢加索爲什麼不保存圖像緩存供脫機使用?

Picasso.with(getContext()) 
    .load(userInfo.getUserPictureUri()) 
    .networkPolicy(NetworkPolicy.OFFLINE) 
    .resize(80, 80) 
    .error(R.drawable.profile_picture) 
    .centerCrop() 
    .into(imageView_ProfilePictureSide, new Callback() { 
     @Override 
     public void onSuccess() { 
     } 

     @Override 
     public void onError() { 
      // Try again if cache failed 
      Picasso.with(getActivity()) 
       .load(userInfo.getUserPictureUri()) 
       .error(R.drawable.profile_picture) 
       .into(imageView_ProfilePictureSide); 
     } 
    }); 
+0

數據從一個GET請求來嗎? – Bawa

+0

哪些數據?雅,圖像的URL是得到請求 –

+0

https://stackoverflow.com/questions/23978828/how-do-i-use-disk-caching-in-picasso –

回答

1

添加OkHttp到應用程序模塊的gradle這個構建文件:

compile 'com.squareup.picasso:picasso:2.5.2' 
compile 'com.squareup.okhttp:okhttp:2.4.0' 

畢加索使用HTTP客戶端請求Disk Cache操作,從而可以使你自己的HTTP請求頭具有財產Cache-Controlmax-age並創建自己的靜態畢加索實例,而不是默認的畢加索通過使用Okhttp

無論是Okhttppicasso庫由squareup團隊提供。

參考文獻:How do I use disk caching in Picasso?Github issue about disk cache,兩個問題已經被@傑克 - 沃頓回答 - >Question1Question2