public void FetchjsonVideo( String url, final String code, final String pagenumber, final boolean saveToDB, final String parentcode, final String classfunctionname, final String retainorDelete, final JsonResponseInterfaceArray callback) { Log.e("videeoooo", "videoooo"); String tag_json_arry = "json_array_req"; JsonArrayRequest req = new JsonArrayRequest( url, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { Log.i("res", response.toString()); if (response != null && response.length() > 0) { try { HashMap<String, String> hash = new HashMap<String, String>(); hash.put(Constants.code, code); hash.put(Constants.pagenumber, pagenumber); hash.put(Constants.newsdata, response.toString()); String expiry = null; long sysTime = SystemClock.elapsedRealtime() / 1000; expiry = String.valueOf(sysTime + String.valueOf(24 * 60 * 60)); hash.put(Constants.expiry, expiry); hash.put(Constants.logTime, String.valueOf(sysTime)); callback.dataFromApi(response, classfunctionname); if (saveToDB) { hash.put(Constants.parentCode, parentcode); if (retainorDelete.equalsIgnoreCase("delete")) { new deleteParentCode().execute(parentcode); } // meeranew new InsertDataToDatabase().execute(hash); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.d(TAG, "Error: " + error.getMessage()); int statuscode = -1; if (error != null) { if (error.networkResponse != null) { statuscode = error.networkResponse.statusCode; } } callback.ErrorResponseVolley(statuscode, classfunctionname); } }); AppController.getInstance().addToRequestQueue(req, tag_json_arry); }
public void FetchjsonFromurl( String url, final String code, final String pagenumber, final boolean saveToDB, final String parentcode, final String classfunctionname, final String retainorDelete, final JsonResponseInterface callback) { Log.e("url", url + "fetchjsonfromurl"); String tag_json_obj = "json_obj_req"; JsonObjectRequest jsonObjReq = new JsonObjectRequest( url, null, new Response.Listener<JSONObject>() { @SuppressWarnings("unchecked") @Override public void onResponse(JSONObject object) { Log.i("obje", object.toString()); HashMap<String, String> hash = new HashMap<String, String>(); hash.put(Constants.code, code); hash.put(Constants.pagenumber, pagenumber); hash.put(Constants.newsdata, object.toString()); String expiry = null; long sysTime = SystemClock.elapsedRealtime() / 1000; try { if (object.has("header")) { JSONObject header = object.getJSONObject("header"); if (header.has("expiryTime")) { expiry = String.valueOf( sysTime + Long.valueOf(header.get("expiryTime").toString())); } else { expiry = String.valueOf(sysTime + String.valueOf(24 * 60 * 60)); } } else { expiry = String.valueOf(sysTime + String.valueOf(24 * 60 * 60)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } hash.put(Constants.expiry, expiry); hash.put(Constants.logTime, String.valueOf(sysTime)); responseInterface = callback; responseInterface.dataFromApi(object, classfunctionname); if (saveToDB) { hash.put(Constants.parentCode, parentcode); if (retainorDelete.equalsIgnoreCase("delete")) { new deleteParentCode().execute(parentcode); } // meeranew new InsertDataToDatabase().execute(hash); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("eroorrr", "error " + error.getMessage() + "****" + error.networkResponse); VolleyLog.d(TAG, "Error: " + error.getMessage()); int statuscode = -1; if (error != null) { if (error.networkResponse != null) { statuscode = error.networkResponse.statusCode; } } responseInterface = callback; responseInterface.ErrorResponseVolley(statuscode, classfunctionname); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> header = new HashMap<String, String>(); if (classfunctionname.contains("getSpamDialog")) { if (credentials != null && credentials.length() > 0) { header.put("Authorization", "Bearer " + id_token); } else { header.put("User-Agent", "Android"); } } else { header.put("User-Agent", "Android"); } return header; } }; // Adding request to request queue AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj); }