Android 毕加索,OkHttp:无法添加LoggingInterceptor
我在用毕加索做我的应用。我需要在毕加索的请求中添加一个LoggingInterceptor。我用的是毕加索2.5.0。以及OKHTTP2.2.0 我做了以下工作:Android 毕加索,OkHttp:无法添加LoggingInterceptor,android,picasso,okhttp,Android,Picasso,Okhttp,我在用毕加索做我的应用。我需要在毕加索的请求中添加一个LoggingInterceptor。我用的是毕加索2.5.0。以及OKHTTP2.2.0 我做了以下工作: public class CustomPicasso { public static final String TAG = "Picasso"; private static Picasso instance; public static Picasso getInstance(Context context) { if
public class CustomPicasso {
public static final String TAG = "Picasso";
private static Picasso instance;
public static Picasso getInstance(Context context) {
if (instance == null) {
Log.d(TAG, "initializing a new instance");
instance = new Picasso.Builder(context.getApplicationContext())
.downloader(new OkHttpDownloader(getClient()))
.build();
}
return instance;
}
public static OkHttpClient getClient() {
OkHttpClient picassoOkHttpClient = new OkHttpClient();
if (BuildConfig.DEBUG) {
Log.d(TAG, "Adding network interceptors to picasso instance");
picassoOkHttpClient.interceptors().add(new LoggingInterceptor("PicassoLog"));
}
return picassoOkHttpClient;
}
}
public static class LoggingInterceptor implements Interceptor {
public String TAG = "LoggingInterceptor";
public LoggingInterceptor() {};
public LoggingInterceptor(String tag) {
TAG = tag;
Log.d(TAG, "added logginginterceptor");
}
@Override
public Response intercept(Chain chain) throws IOException {
Log.d(TAG, "Intercepting requests");
Request request = chain.request();
long t1 = System.nanoTime();
Log.d(TAG, String.format("Sending request %s on %s%n%s", request.url(), chain.connection(), request.headers()));
Response response = chain.proceed(request);
long t2 = System.nanoTime();
Log.d(TAG, String.format("Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers()));
return response;
}
}
我没有看到对我的图像URL的任何请求。请告诉我我做错了什么 如果使用
okhttp 2.1.0
,可能会得到预期的结果。这就是毕加索2.5.0所依赖的okhttp
版本(参见其pom.xml
文件)