Android Volley ImageLoader – BitmapLruCache parameter?

import android.graphics.Bitmap; import android.support.v4.util.LruCache; public class BitmapLruCache extends LruCache<String, Bitmap> implements ImageCache { public static int getDefaultLruCacheSize() { final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; return cacheSize; } public BitmapLruCache() { this(getDefaultLruCacheSize()); } public BitmapLruCache(int sizeInKiloBytes) { super(sizeInKiloBytes); } @Override protected int sizeOf(String key, Bitmap value) { … Read more

Best way to incorporate Volley (or other library) into Android Studio project

As pointed out by others as well, Volley is officially available on Github: Add this line to your gradle dependencies for volley: compile ‘com.android.volley:volley:1.0.0’ To install volley from source read below: I like to keep the official volley repository in my app. That way I get it from the official source and can get updates … Read more

Upload an image using Google Volley

I have an example to upload images by Google Volley. Take a look: package net.colaborativa.exampleapp.api; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntityBuilder; import com.android.volley.AuthFailureError; import com.android.volley.NetworkResponse; import com.android.volley.Request; import com.android.volley.Response; import com.android.volley.Response.ErrorListener; import com.android.volley.Response.Listener; import com.android.volley.VolleyLog; import com.android.volley.toolbox.HttpHeaderParser; public class PhotoMultipartRequest<T> extends … Read more

Volley send JSONObject to server with POST method

You can use the following working sample code. I have tested. Hope this helps! try { jsonBody = new JSONObject(); jsonBody.put(“Title”, “VolleyApp Android Demo”); jsonBody.put(“Author”, “BNK”); jsonBody.put(“Date”, “2015/08/26”); requestBody = jsonBody.toString(); StringRequest stringRequest = new StringRequest(1, url, new Response.Listener<String>() { @Override public void onResponse(String response) { textView.setText(response); } }, new Response.ErrorListener() { @Override public void … Read more

Android: How to return async JSONObject from method using Volley?

For your comment I think that async is provided by Volley automatically. So i need to know how to get JSON data into the first snippet IMO, instead of your first snippet, you can try the following way (of course, you can replace JSONArray request by JSONObject request): VolleyResponseListener listener = new VolleyResponseListener() { @Override … Read more

How to clear the volley cache automatically?

Google Volley provides 2 ways to clear an item from the Cache: AppController.getInstance().getRequestQueue().getCache().remove(key); and AppController.getInstance().getRequestQueue().getCache().invalidate(key, fullExpire); Remove means you are removing the actual cached data. Invalidate means you are just marking the data as invalid. So volley will check with the server whether the data is still valid. The full expire determines whether to use … Read more

Android volley sending data twice

No need to use connection.setChunkedStreamingMode(0); to avoid volley sending data twice bug. you need to set retry policy for current request : JsonObjectRequest jsonObjReq = new JsonObjectRequest(…); jsonObjReq.setRetryPolicy(new DefaultRetryPolicy( 0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));