StringRequest stringRequest = new StringRequest(Request.Method.POST, UrlEndPoints.interAd,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("Response::", response);
try {
int success;
JSONObject jsonObject = new JSONObject(response);
Log.e("jObj_AppURL", String.valueOf(jsonObject));
success = jsonObject.getInt(SUCCESS);
if (success == 1) {
JSONArray data = jsonObject.getJSONArray(RESPONSE);
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
appImg = c.getString(APPIMG);
appName = c.getString(APPNAME);
appPackages = c.getString(PKG);
InterAdModel interAdModel = new InterAdModel();
interAdModel.setAppImg(appImg);
interAdModel.setAppName(appName);
interAdModel.setAppPackages(appPackages);
interAdModelArrayList.add(interAdModel);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("erorr::", error.toString());
Toast.makeText(SplashActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
//for check service is correctly functioning use package name "com.whatsweb.whatscan.whatsappweb.whatscanforwhatweb"
Map<String, String> params = new HashMap<>();
params.put("task", "get_interad_apps");
params.put("package", getPackageName());
return params;
}
};
int socketTimeout = 30000;
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
RequestQueue requestQueue = Volley.newRequestQueue(SplashActivity.this);
requestQueue.add(stringRequest);
I am facing error while parsing the JSON object. I am adding two fields,ie. the task and the package name of the application using Map, but it is always throwing the Exceptions. Very rarely I get the actual data. Sometimes It throws only EOFException while sometimes NoConnection error.