com.android.volley.Network Java Examples
The following examples show how to use
com.android.volley.Network.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Crossbow.java From CrossBow with Apache License 2.0 | 6 votes |
public Crossbow(Context context, CrossbowComponents crossbowComponents) { this.context = context.getApplicationContext(); this.requestQueue = crossbowComponents.provideRequestQueue(); this.imageLoader = crossbowComponents.provideImageLoader(); this.imageCache = crossbowComponents.provideImageCache(); Cache cache = crossbowComponents.provideCache(); Network network = crossbowComponents.provideNetwork(); FileDelivery fileDelivery = new BasicFileDelivery(); FileStack fileStack = new BasicFileStack(context); fileQueue = new FileQueue(fileDelivery, fileStack); fileQueue.start(); fileImageLoader = new FileImageLoader(fileQueue, imageCache); syncDispatcher = new SyncDispatcher(cache, network); }
Example #2
Source File: RequestQueueTest.java From volley with Apache License 2.0 | 6 votes |
@Test public void publicMethods() throws Exception { // Catch-all test to find API-breaking changes. assertNotNull( RequestQueue.class.getConstructor( Cache.class, Network.class, int.class, ResponseDelivery.class)); assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class)); assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class)); assertNotNull(RequestQueue.class.getMethod("start")); assertNotNull(RequestQueue.class.getMethod("stop")); assertNotNull(RequestQueue.class.getMethod("getSequenceNumber")); assertNotNull(RequestQueue.class.getMethod("getCache")); assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class)); assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class)); assertNotNull(RequestQueue.class.getMethod("add", Request.class)); assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class)); }
Example #3
Source File: CloudBackendFragment.java From io2014-codelabs with Apache License 2.0 | 6 votes |
private RequestQueue newRequestQueue(Context context) { // define cache folder File rootCache = context.getExternalCacheDir(); if (rootCache == null) { rootCache = context.getCacheDir(); } File cacheDir = new File(rootCache, DEFAULT_CACHE_DIR); cacheDir.mkdirs(); HttpStack stack = new HurlStack(); Network network = new BasicNetwork(stack); DiskBasedCache diskBasedCache = new DiskBasedCache(cacheDir, DEFAULT_DISK_USAGE_BYTES); RequestQueue queue = new RequestQueue(diskBasedCache, network); queue.start(); return queue; }
Example #4
Source File: RequestQueueTest.java From SaveVolley with Apache License 2.0 | 6 votes |
@Test public void publicMethods() throws Exception { // Catch-all test to find API-breaking changes. assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class, ResponseDelivery.class)); assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class, int.class)); assertNotNull(RequestQueue.class.getConstructor(Cache.class, Network.class)); assertNotNull(RequestQueue.class.getMethod("start")); assertNotNull(RequestQueue.class.getMethod("stop")); assertNotNull(RequestQueue.class.getMethod("getSequenceNumber")); assertNotNull(RequestQueue.class.getMethod("getCache")); assertNotNull(RequestQueue.class.getMethod("cancelAll", RequestQueue.RequestFilter.class)); assertNotNull(RequestQueue.class.getMethod("cancelAll", Object.class)); assertNotNull(RequestQueue.class.getMethod("add", Request.class)); assertNotNull(RequestQueue.class.getDeclaredMethod("finish", Request.class)); }
Example #5
Source File: ImageLoader.java From android-discourse with Apache License 2.0 | 5 votes |
private static RequestQueue newRequestQueue(Context context) { // On HC+ use HurlStack which is based on HttpURLConnection. Otherwise fall back on // AndroidHttpClient (based on Apache DefaultHttpClient) which should no longer be used // on newer platform versions where HttpURLConnection is simply better. Network network = new BasicNetwork(Utils.hasHoneycomb() ? new HurlStack() : new HttpClientStack(AndroidHttpClient.newInstance(Utils.getUserAgent(context)))); Cache cache = new DiskBasedCache(getDiskCacheDir(context, CACHE_DIR), DEFAULT_DISK_USAGE_BYTES); RequestQueue queue = new RequestQueue(cache, network); queue.start(); return queue; }
Example #6
Source File: ApiInvoker.java From openapi-generator with Apache License 2.0 | 5 votes |
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) { INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout); setUserAgent("OpenAPI-Generator/1.0.0/android"); // Setup authentications (key: authentication name, value: authentication). INSTANCE.authentications = new HashMap<String, Authentication>(); INSTANCE.authentications.put("api_key", new ApiKeyAuth("header", "api_key")); // TODO: comment out below as OAuth does not exist //INSTANCE.authentications.put("petstore_auth", new OAuth()); // Prevent the authentications from being modified. INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications); }
Example #7
Source File: Volley.java From android-discourse with Apache License 2.0 | 5 votes |
/** * 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; }
Example #8
Source File: Volley.java From product-emm with Apache License 2.0 | 5 votes |
/** * 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; }
Example #9
Source File: Volley.java From product-emm with Apache License 2.0 | 5 votes |
/** * 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; }
Example #10
Source File: WaspTest.java From wasp with Apache License 2.0 | 5 votes |
public WaspTest() throws Exception { File cacheDir = new File(context.getCacheDir(), "volley"); Network network = new BasicNetwork(new OkHttpStack(new OkHttpClient())); ResponseDelivery delivery = new ExecutorDelivery(executor); requestQueue = new RequestQueue(new DiskBasedCache(cacheDir), network, 4, delivery); requestQueue.start(); server.start(); }
Example #11
Source File: Volley.java From volley with Apache License 2.0 | 5 votes |
/** * 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 = null; 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(userAgent); } 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 DiskLruBasedCache(cacheDir), network); queue.start(); return queue; }
Example #12
Source File: Volley.java From volley with Apache License 2.0 | 5 votes |
/** * 不带缓存的requestQueue * newNoCacheRequestQueue * @param context * @param stack * @return * @since 3.5 */ public static RequestQueue newNoCacheRequestQueue(Context context) { String userAgent = null; try { String packageName = context.getPackageName(); PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0); userAgent = packageName + "/" + info.versionCode; } catch (NameNotFoundException e) { } HttpStack stack = null; if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(userAgent); } 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 NoCache(), network); queue.start(); return queue; }
Example #13
Source File: Volley.java From okulus with Apache License 2.0 | 5 votes |
/** * 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; }
Example #14
Source File: Volley.java From FeedListViewDemo with MIT License | 5 votes |
/** * 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; }
Example #15
Source File: Volley.java From android_tv_metro with Apache License 2.0 | 5 votes |
/** * 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; }
Example #16
Source File: Volley.java From android_tv_metro with Apache License 2.0 | 5 votes |
public static RequestQueue newRequestQueue(Context context, HttpStack stack, String dir, int cacheSize) { File cacheDir = new File(context.getCacheDir(), 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, cacheSize), network); queue.start(); return queue; }
Example #17
Source File: Volley.java From barterli_android with Apache License 2.0 | 5 votes |
/** * 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(userAgent); } 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, new BasicUrlRewriter()); queue.start(); return queue; }
Example #18
Source File: Volley.java From WayHoo with Apache License 2.0 | 5 votes |
/** * 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; }
Example #19
Source File: Volley.java From SimplifyReader with Apache License 2.0 | 5 votes |
/** * 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; }
Example #20
Source File: ApiInvoker.java From swaggy-jenkins with MIT License | 5 votes |
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) { INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout); setUserAgent("OpenAPI-Generator/1.0.0/android"); // Setup authentications (key: authentication name, value: authentication). INSTANCE.authentications = new HashMap<String, Authentication>(); INSTANCE.authentications.put("jenkins_auth", new HttpBasicAuth()); INSTANCE.authentications.put("jwt_auth", new ApiKeyAuth("header", "Authorization")); // Prevent the authentications from being modified. INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications); }
Example #21
Source File: Volley.java From device-database with Apache License 2.0 | 5 votes |
/** * 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; }
Example #22
Source File: LimitingRequestQueue.java From odyssey with GNU General Public License v3.0 | 5 votes |
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; }
Example #23
Source File: ApiInvoker.java From swagger-aem with Apache License 2.0 | 5 votes |
public static void initializeInstance(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery, int connectionTimeout) { INSTANCE = new ApiInvoker(cache, network, threadPoolSize, delivery, connectionTimeout); setUserAgent("OpenAPI-Generator/1.0.0/android"); // Setup authentications (key: authentication name, value: authentication). INSTANCE.authentications = new HashMap<String, Authentication>(); INSTANCE.authentications.put("aemAuth", new HttpBasicAuth()); // Prevent the authentications from being modified. INSTANCE.authentications = Collections.unmodifiableMap(INSTANCE.authentications); }
Example #24
Source File: Volley.java From CrossBow with Apache License 2.0 | 5 votes |
/** * 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; }
Example #25
Source File: Volley.java From android-project-wo2b with Apache License 2.0 | 5 votes |
/** * 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; }
Example #26
Source File: Volley.java From android-common-utils with Apache License 2.0 | 5 votes |
/** * 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; }
Example #27
Source File: WearCrossbowComponents.java From CrossBow with Apache License 2.0 | 4 votes |
@Override public Network onCreateNetwork(HttpStack httpStack) { return new PlayNetwork(getContext()); }
Example #28
Source File: DefaultCrossbowComponents.java From CrossBow with Apache License 2.0 | 4 votes |
public RequestQueue onCreateRequestQueue(Cache cache, Network network) { RequestQueue requestQueue = new RequestQueue(cache, network); requestQueue.start(); return requestQueue; }
Example #29
Source File: DefaultCrossbowComponents.java From CrossBow with Apache License 2.0 | 4 votes |
public Network onCreateNetwork(HttpStack httpStack) { return new BasicNetwork(httpStack); }
Example #30
Source File: WearCrossbowComponents.java From CrossBow with Apache License 2.0 | 4 votes |
@Override public RequestQueue onCreateRequestQueue(Cache cache, Network network) { RequestQueue requestQueue = new RequestQueue(cache, network, 3); requestQueue.start(); return requestQueue; }