Darshan S S Darshan S S - 1 year ago 149
Android Question

Volley PATCH is not working in Pre-lollipop deives

volley + gson PATCH is not working in pre-lollipo [Kitkat] devices.
Here is the code.....

GsonRequestJson gsonRequestJson = new GsonRequestJson(Request.Method.PATCH,url, WishlistItems.class, headers, jsonObject, new Response.Listener<WishlistItems>() {
public void onResponse(WishlistItems response) {
Toast.makeText(mContext, "Successfully removed from wishlist", Toast.LENGTH_SHORT).show();
// dialog.dismiss();

Gson gson = new Gson();
String jsonFavorites = gson.toJson(new ArrayList<>(Arrays.asList(response)));
MainActivity.tinyDB.putString(Constants.MY_SHARED_PREF_MARKEDITEMS, jsonFavorites);

}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Toast.makeText(mContext, "Failed", Toast.LENGTH_LONG)
Log.d("Error---", "-----" + error.toString());

Answer Source

Try this,

Change Request.Method.PATCH to Request.Method.POST, and then change the header type to PUT as below.

HashMap<String, String> headers = new HashMap<String, String>();
                            headers.put("Authorization", "JWT " + Constants.load(mContext,Constants.MY_SHARED_PREF_TOKEN));
                            headers.put("Content-Type", "application/json");
                            headers.put("X-HTTP-Method-Override", "PUT");

PS: This is just a hack but not the actual solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download