This OkHttpStack is no longer supported in OkHttp2.0: https://gist.github.com/JakeWharton/5616899
What is the current pattern to integrate OkHttp 2.0.0 with Volley?
This OkHttpStack is no longer supported in OkHttp2.0: https://gist.github.com/JakeWharton/5616899
What is the current pattern to integrate OkHttp 2.0.0 with Volley?
You must use okhttp-urlconnection module that implements the java.net.HttpURLConnection API, so:
Download or set a dependency for okhttp-urlconnection
Rewrite your OkHttpStack to make use of the OkUrlFactory class:
public class OkHttpStack extends HurlStack {
private final OkUrlFactory okUrlFactory;
public OkHttpStack() {
this(new OkUrlFactory(new OkHttpClient()));
}
public OkHttpStack(OkUrlFactory okUrlFactory) {
if (okUrlFactory == null) {
throw new NullPointerException("Client must not be null.");
}
this.okUrlFactory = okUrlFactory;
}
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
return okUrlFactory.open(url);
}
}
compile 'com.squareup.okhttp:okhttp:2.0.0' compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0' compile 'com.squareup.okio:okio:1.0.1'
–
Curiel You can use this also
import com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation
* which uses OkHttp as its transport.
*/
public class OkHttpStack extends HurlStack {
private final OkUrlFactory mFactory;
public OkHttpStack() {
this(new OkHttpClient());
}
public OkHttpStack(OkHttpClient client) {
if (client == null) {
throw new NullPointerException("Client must not be null.");
}
mFactory = new OkUrlFactory(client);
}
}
You can also do this now without the dependency on HttpURLConnection:
© 2022 - 2024 — McMap. All rights reserved.
HttpStack
support. – Loseff