How to implement Android Volley with OkHttp 2.0?

后端 未结 3 1225
北海茫月
北海茫月 2020-12-12 22:58

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?<

3条回答
  •  执念已碎
    2020-12-12 23:30

    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);
        }
    }
    

提交回复
热议问题