My java code is as follows, when the user fills the required fields then given a response from the server whether the user exists or not.
else {
StringRequest stringRequest = new StringRequest(Request.Method.POST,
SERVER_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String code = jsonObject.getString("code");
String message = jsonObject.getString("message");
builder.setTitle("Server response");
builder.setMessage(message);
displayAlert(code);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("name", Username);
params.put("email", Email);
params.put("password", Passwrd);
return params;
}
@Override
public RetryPolicy getRetryPolicy() {
setRetryPolicy(new DefaultRetryPolicy(
5000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
return super.getRetryPolicy();
}
};
MySingleton.getInstance(Register.this).addToRequestQueue(stringRequest);
}
}
}
});
}
and the jsonObject response I need is
{
"code": "reg failed",
"message": "user exists"
}