Search in sources :

Example 6 with Network

use of com.android.volley.Network in project TaEmCasa by Dionen.

the class Volley method newRequestQueue.

/**
     * 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;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) RequestQueue(com.android.volley.RequestQueue) Network(com.android.volley.Network) File(java.io.File)

Example 7 with Network

use of com.android.volley.Network in project DesignLibrary by StylingAndroid.

the class VolleySingleton method getRequestQueue.

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;
}
Also used : BasicNetwork(com.android.volley.toolbox.BasicNetwork) HurlStack(com.android.volley.toolbox.HurlStack) RequestQueue(com.android.volley.RequestQueue) Network(com.android.volley.Network) BasicNetwork(com.android.volley.toolbox.BasicNetwork) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache) Cache(com.android.volley.Cache) DiskBasedCache(com.android.volley.toolbox.DiskBasedCache)

Aggregations

Network (com.android.volley.Network)7 RequestQueue (com.android.volley.RequestQueue)7 PackageInfo (android.content.pm.PackageInfo)6 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 File (java.io.File)6 Cache (com.android.volley.Cache)1 BasicNetwork (com.android.volley.toolbox.BasicNetwork)1 DiskBasedCache (com.android.volley.toolbox.DiskBasedCache)1 HurlStack (com.android.volley.toolbox.HurlStack)1