1) 导入Volley(目前没有官方的jar包,需要自己下载源码编译)
2) 导入OkHttp,okhttp-urlconnection
3) 创建OkHttpStack
public class OkHttpStack extends HurlStack { private OkHttpClient okHttpClient; /** * Create a OkHttpStack with default OkHttpClient. */ public OkHttpStack() { this(new OkHttpClient()); } /** * Create a OkHttpStack with a custom OkHttpClient * * @param okHttpClient Custom OkHttpClient, NonNull */ public OkHttpStack(OkHttpClient okHttpClient) { this.okHttpClient = okHttpClient; } @Override protected HttpURLConnection createConnection(URL url) throws IOException { OkUrlFactory okUrlFactory = new OkUrlFactory(okHttpClient); return okUrlFactory.open(url); } }
4) 创建Volley队列
Volley.newRequestQueue(context, new OkHttpStack());
时间: 2024-11-05 11:58:04