0

I have an application that communicates with a web server to retrieve some data, the application always working fine but now is showing this error :

javax.net.ssl.SSLException: Connection closed by peer

This only occur when i use a android < 4.4 if is 6.0 > it is working fine

 public void volleyJsonObjectRequest(String url){

    String  REQUEST_TAG = "com.androidtutorialpoint.volleyJsonObjectRequest";
    pDialog = new ProgressDialog(LoginActivity.this);
    pDialog.setMessage("Efetuando login..");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();

    StringRequest postRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {

                        json      = new JSONObject(response);
                        userId    = json.getString("userid");
                        userType  = json.getString("usertype");
                        dbversion = json.getInt("dbversion");
                        success   = json.getInt(TAG_SUCCESS);
                        message   = json.getString(TAG_MESSAGE);

                        if (pDialog != null && pDialog.isShowing()) {
                            pDialog.dismiss();
                        }

                        enviadoComSucesso();


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    if (pDialog != null && pDialog.isShowing()) {
                        pDialog.dismiss();
                    }
                    userMsg("Não foi possível fazer conexão, por favor tenta novamente.");
                }
            }
    ) {
        @Override
        protected Map<String, String> getParams()
        {
            String usuario  = LoginActivity.this.userTemp;
            String password = LoginActivity.this.passTemp;

            Map<String, String> param = new HashMap<>();

            //ENVIO DOS DADOS DE AVALIAÇÕES
            param.put("usuario", usuario);
            param.put("password", password);


            return param;
        }
    };
    // Adding JsonObject request to request queue
    AppSingleton.getInstance(getApplicationContext()).addToRequestQueue(postRequest,REQUEST_TAG);
    postRequest.setRetryPolicy(new DefaultRetryPolicy(
            2000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
}

Why is this error showing now? All my applications now have this error. When i see this error i search and found this solution by Sticky

The issue was due to TLSv1 being disabled on backend. Depending on the case there can be two approach to address this issue. 1. Enable TLSv1 on backend server. 2. As suggested, update the SSLEngine to support higher TLS versions on mobile app.

But i'm facing dificcult because is not VOLLEY APROACH, what i must do?

Wavrik
  • 61
  • 9

1 Answers1

1

I have faced this problem a few months ago and the solution was to enable TLSv1 Protocol from the backend

Check this

SSL protocols supported by devices lower than 4.4 "TLSv1" and "SSLv3"

SSL protocols supported by devices higher than 4.4 "TLSv1", "TLSv1.1" and "TLSv1.2"

there is no problem with your Volley code

Biro Nader
  • 119
  • 5