Created
May 8, 2016 17:10
-
-
Save VassilisPallas/3287db2afc6a003a1f1be8a5a79c6235 to your computer and use it in GitHub Desktop.
Empty Request for Volley
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.android.volley.NetworkResponse; | |
import com.android.volley.ParseError; | |
import com.android.volley.Response; | |
import com.android.volley.toolbox.HttpHeaderParser; | |
import com.android.volley.toolbox.JsonObjectRequest; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import java.io.UnsupportedEncodingException; | |
/** | |
* Created by vspallas on 16/02/16. | |
*/ | |
public class EmptyRequest extends JsonObjectRequest { | |
public EmptyRequest(int method, String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) { | |
super(method, url, jsonRequest, listener, errorListener); | |
} | |
public EmptyRequest(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) { | |
super(url, jsonRequest, listener, errorListener); | |
} | |
@Override | |
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) { | |
try { | |
String jsonString = new String(response.data, | |
HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)); | |
JSONObject result = null; | |
if (jsonString != null && jsonString.length() > 0) | |
result = new JSONObject(jsonString); | |
return Response.success(result, | |
HttpHeaderParser.parseCacheHeaders(response)); | |
} catch (UnsupportedEncodingException e) { | |
return Response.error(new ParseError(e)); | |
} catch (JSONException je) { | |
return Response.error(new ParseError(je)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment