Darshan S S Darshan S S - 15 days ago 12
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());


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.