Skip to content

Instantly share code, notes, and snippets.

@yishai-glide
Created April 14, 2015 18:16
Show Gist options
  • Save yishai-glide/1f856656ed38ff466804 to your computer and use it in GitHub Desktop.
Save yishai-glide/1f856656ed38ff466804 to your computer and use it in GitHub Desktop.
a class that inherits JsonArrayRequest but allows storing POST data
package com.android.volley.toolbox;
import org.json.JSONArray;
import android.text.TextUtils;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
public class MyJsonArrayRequest extends JsonArrayRequest {
private byte[] mPostBody = null;
public MyJsonArrayRequest(String url, String data, Listener<JSONArray> listener, ErrorListener errorListener) {
super(url, listener, errorListener);
if(!TextUtils.isEmpty(data)) {
mPostBody = data.getBytes();
}
}
@Override
public byte[] getBody() {
if(mPostBody == null || mPostBody.length == 0) {
return super.getBody();
} else {
return mPostBody;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment