Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Método utilizado para fazer requisições GET ao webservice retornando um objeto no formato Json*/
- /* Enquanto a requisição esta sendo processada, aparece um Dialog de "carregando"*/
- public void get(Context contexto, String url, final VolleyCallbackObject callback){
- final RequestQueue request = Volley.newRequestQueue(contexto);
- final JsonObjectRequest requisicao = new JsonObjectRequest(Request.Method.GET, url,
- new Response.Listener<JSONObject>(){
- @Override
- public void onResponse(JSONObject response) {
- callback.onSuccess(response);
- dialog.dismiss();
- }
- }, new Response.ErrorListener(){
- @Override
- public void onErrorResponse(VolleyError error ) {
- Log.i("ERROR", "onErrorResponse: " + error );
- dialog.dismiss();
- }
- });
- int socketTimeout = 30000;//30 seconds - change to what you want
- RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
- requisicao.setRetryPolicy(policy);
- request.add(requisicao);
- dialog = new ProgressDialog(contexto);
- dialog.setMessage("Carregando....");
- dialog.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment