2
我試圖從網絡服務器下載和緩存與畢加索的圖像。我發現了一個解決方案就在這裏:https://stackoverflow.com/a/30686992/6884064與OKHttp不顯示圖像的畢加索:日誌錯誤
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);
Picasso.with(this)
.load("http://i.imgur.com/Q85lste.jpg")
.networkPolicy(NetworkPolicy.OFFLINE)
.into(coverImg);
的build.gradle:
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
當我運行它,我的圖像佔位符消失,但新的圖像不加載
運行。日誌給我這個:
D/Picasso: Main created [R0] Request{http://i.imgur.com/Q85lste.jpg}
D/Picasso: Dispatcher enqueued [R0]+6ms
D/Picasso: Hunter executing [R0]+7ms
W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.test.example1/cache/picasso-cache/journal.tmp
D/Picasso: Dispatcher batched [R0]+45ms for error
D/Picasso: Dispatcher delivered [R0]+246ms
D/Picasso: Main errored [R0]+246ms
任何人都知道這是怎麼回事?謝謝!
編輯:
它的工作與此代碼:
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.networkInterceptors().add(new Interceptor() {
@Override
public Response intercept(Interceptor.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(getCacheDir(), Integer.MAX_VALUE));
OkHttpDownloader okHttpDownloader = new OkHttpDownloader(okHttpClient);
Picasso picasso = new Picasso.Builder(this).downloader(okHttpDownloader).build();
picasso.load("http://i.imgur.com/test.jpg").into(coverImg);
我只有第一個權限集。現在調整它,並嘗試在兩個(我的手機和模擬器。在我的手機上沒有任何改變 - >仍然得到相同的錯誤在我的模擬器中,我收到一個不同的錯誤說:D/NetworkSecurityConfig:沒有指定的網絡安全配置,使用平臺默認 –
您的權利,我從我的應用程序複製這些代碼和忘記檢查他們:。!。d –
我會盡力找到解決與其他方法來幫助你 –