StringRequest stringRequest = new StringRequest (Request.Method.GET, url, new Response.Listener () {@Override public void onResponse (String response) {Log.e (проверка "onResponseSuccess", response.toString () + "");
открытый класс VollyResponse {
private Context mContext;
private BaseActivity baseActivity;
public VollyResponse(Context context) {
this.mContext = context;
baseActivity = (BaseActivity) context;
}
public void sendRequest(String body, final GetVollyResponse getVollyResponse) {
Log.e("URL", body);
// baseActivity.appDialogs.showAlertDialog();
//baseActivity.appDialogs.showMaterialProgress(mContext);
StringRequest stringRequest = new StringRequest(body, new Response.Listener<String>() {
@Override public void onResponse(String response) {
// baseActivity.appDialogs.hideMaterialProgress();
try {
JSONObject result = new JSONObject(response);
Log.e("Response", result + "");
if (result.getString("status").equalsIgnoreCase("true")) {
getVollyResponse.onSuccess(result);
} else {
getVollyResponse.onFailure(result.getString("message"));
}
}
catch(JSONException e) {
e.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override public void onErrorResponse(VolleyError error) {
try {
getVollyResponse.onVollyFailure(error);
}
catch(Exception e) {
e.printStackTrace();
}
}
});
com.android.volley.RequestQueue requestQueue = Volley.newRequestQueue(mContext);
requestQueue.add(stringRequest);
}
}
открытый интерфейс GetVollyResponse {
public void onSuccess(JSONObject result) throws Exception;
public void onFailure(String message) throws Exception;
public void onVollyFailure(VolleyError error) throws Exception;
}