public static RequestQueue newRequestQueueForTest(final Context context, final OkHttpClient okHttpClient) { final File cacheDir = new File(context.getCacheDir(), "volley"); final Network network = new BasicNetwork(new OkHttpStack(okHttpClient)); final ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor()); final RequestQueue queue = new RequestQueue( new DiskBasedCache(cacheDir), network, 4, responseDelivery); queue.start(); return queue; }
queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue = new RequestQueue(new DiskBasedCache(cacheDir, maxDiskCacheBytes), network);
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link android.content.Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
/** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. * * @param context A {@link Context} to use for creating the cache dir. * @param stack An {@link HttpStack} to use for the network, or null for default. * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); RequestQueue queue = new RequestQueue(cache, network); queue.start(); // clear all volley caches. queue.add(new ClearCacheRequest(cache, null));
RequestQueue queue = Volley.newRequestQueue(this); Network network = new BasicNetwork(new OkHttpStack()); RequestQueue queue = new RequestQueue(new DiskBasedCache(new File(getCacheDir(), "volley")), network); queue.start();
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); DiskBasedCache cache = new DiskBasedCache(cacheDir); RequestQueue queue = new RequestQueue(cache, network); queue.start();
//Specific test queue that uses a singleThreadExecutor instead of the mainLooper for testing purposes. public RequestQueue newVolleyRequestQueueForTest(final Context context) { File cacheDir = new File(context.getCacheDir(), "cache/volley"); Network network = new BasicNetwork(new HurlStack()); ResponseDelivery responseDelivery = new ExecutorDelivery(Executors.newSingleThreadExecutor()); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, responseDelivery); queue.start(); return queue; }
public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new BasicNetwork(stack); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
// Copied from Volley.newRequestQueue(..); source code File cacheDir = new File(context.getCacheDir(), "def_cahce_dir"); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (PackageManager.NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } int threadPoolSize = 1; // means only one request at a time RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, threadPoolSize); queue.start();
// Copied from Volley.newRequestQueue(..); source code File cacheDir = new File(context.getCacheDir(), "def_cahce_dir"); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (PackageManager.NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } int threadPoolSize = 1; // means only one request at a time RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network, threadPoolSize); queue.start();
public static RequestQueue newRequestQueue(Context context, HttpStack stack) { File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); String userAgent = "volley/0"; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } if (stack == null) { if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); } } Network network = new ManualProxyNetwork(new BasicNetwork(stack)); RequestQueue queue = new RequestQueue(new DiskBasedCache(cacheDir), network); queue.start(); return queue; }
@Override public void registerComponents(Context context, Glide glide) { final int retryPolicy = 10000; RequestQueue queue = new RequestQueue( new DiskBasedCache(new File(context.getCacheDir(), "volley")), new BasicNetwork(new HurlStack())) { @Override public <T> Request<T> add(Request<T> request) { request.setRetryPolicy(new DefaultRetryPolicy(retryPolicy, 1, 1); return super.add(request); } }; queue.start(); glide.register(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(queue)); }
public class CustomGlide implements GlideModule { @Override public void applyOptions(Context context, GlideBuilder builder) { } @Override public void registerComponents(Context context, Glide glide) { RequestQueue queue = new RequestQueue( // params hardcoded from Volley.newRequestQueue() new DiskBasedCache(new File(context.getCacheDir(), "volley")), new BasicNetwork(new HurlStack())) { @Override public <T> Request<T> add(Request<T> request) { request.setRetryPolicy(new **DefaultRetryPolicy(10000, 1, 1)**); return super.add(request); } }; queue.start(); glide.register(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(queue)); } }
private RequestQueue getRequestQueue(Context ctx, int nbDlThreads) { // Freely inspired by inner workings of Volley.java and RequestQueue.java; to be watched closely as Volley evolves if (mRequestQueue == null) { BasicNetwork network = new BasicNetwork(new VolleyOkHttp3Stack(TIMEOUT_MS)); File cacheDir = new File(ctx.getCacheDir(), "volley"); // NB : this is dirty, as this value is supposed to be private in Volley.java mRequestQueue = new RequestQueue(new DiskBasedCache(cacheDir), network, nbDlThreads); mRequestQueue.addRequestFinishedListener(this); mRequestQueue.start(); } return mRequestQueue; }
public static RequestQueue newRequestQueue(Context context) { if (InstanceNetwork == null) { InstanceNetwork = new OkNetwork(getDefaultHttpStack()); } if (InstanceCache == null) { File cache = context.getExternalCacheDir(); if (cache == null) { cache = context.getCacheDir(); } File cacheDir = new File(cache, DEFAULT_CACHE_DIR); InstanceCache = new DiskBasedCache(cacheDir); } RequestQueue queue = new RequestQueue(InstanceCache, InstanceNetwork); queue.start(); return queue; }
public RequestQueue getRequestQueue() { if (mRequestQueue == null) { Cache cache = new DiskBasedCache(mCtx.getCacheDir(), 10 * 1024 * 1024); Network network = new BasicNetwork(new HurlStack()); mRequestQueue = new RequestQueue(cache, network); // Don't forget to start the volley request queue mRequestQueue.start(); } return mRequestQueue; }
private RequestQueue getRequestQueue() { if (requestQueue == null) { Cache cache = new DiskBasedCache(context.getCacheDir(), 10 * 1024 * 1024); Network network = new BasicNetwork(new HurlStack()); requestQueue = new RequestQueue(cache, network); requestQueue.start(); } return requestQueue; }
public synchronized static LimitingRequestQueue getInstance(Context context) { if (null == mInstance) { Network network = new BasicNetwork(new HurlStack()); // 10MB disk cache Cache cache = new DiskBasedCache(context.getCacheDir(), 1024 * 1024 * 10); mInstance = new LimitingRequestQueue(cache, network); mInstance.start(); } return mInstance; }
public RequestQueue getRequestQueue() { if (requestQueue == null) { Cache cache = new DiskBasedCache(context.getCacheDir(), CACHE_SIZE); Network network = new BasicNetwork(new HurlStack()); requestQueue = new RequestQueue(cache, network); requestQueue.start(); } return requestQueue; }