Working Error Volley Android

1

I'm creating an Android application that sends via Volley some strings. I would like to know how to work the errors, for example, if the server is offline.

Follow the code for sending the strings:

private void saveNaWeb (final UserObject) {

    StringRequest stringRequest = new StringRequest(Request.Method.POST,
            AppBoloNaHora.URL_SALVAR_USUARIOWEB,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }
    ) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {

            Map<String, String> params = new Hashtable<String, String>();


            params.put("nome", objUsuario.getNome());
            params.put("email", objUsuario.getEmail());
            params.put("telefone", objUsuario.getTelefone());
            params.put("senha", objUsuario.getSenha());
            params.put("latitude", latitude + "");
            params.put("longitude", longitude + "");

            mudarTela();
            return params;
        }
    };

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(
            AppBoloNaHora.WEB_SERVICE_TIMEOUT_MS,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));


    RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
    requestQueue.add(stringRequest);
}

I would like to do a validation, to know if the data was actually sent. So I am just making a check if the cell phone is with the internet to validate the sending / insertion of data in the database.

Thank you.

    
asked by anonymous 20.03.2018 / 21:48

0 answers