Android Volley慢速互联网问题

时间:2017-10-03 11:40:29

标签: android android-volley

您好我在Android中使用Volley for Networking,一切正常,问题出现在慢速互联网错误上,其中超时发生但请求发送到服务器的某个时候它正在处理。有人可以帮助我,即使我尝试增加超时但没有任何帮助。

2 个答案:

答案 0 :(得分:1)

      @Override
   public void onErrorResponse(VolleyError volleyError) {
   String message = null;
   if (volleyError instanceof NetworkError) {
         message = "Cannot connect to Internet...Please check your connection!";
   } else if (volleyError instanceof ServerError) {
         message = "The server could not be found. Please try again after some time!!";
   } else if (volleyError instanceof AuthFailureError) {
         message = "Cannot connect to Internet...Please check your connection!";
   } else if (volleyError instanceof ParseError) {
         message = "Parsing error! Please try again after some time!!";
   } else if (volleyError instanceof NoConnectionError) {
         message = "Cannot connect to Internet...Please check your connection!";
   } else if (volleyError instanceof TimeoutError) {
         message = "Connection TimeOut! Please check your internet connection.";
   }
}

答案 1 :(得分:0)

如果能够在服务器数据库中写入,那么即使在超时后您也可能会收到响应。请将logs放在onResposne和onErrorResponse方法中。

JsonObjectRequest myRequest = new JsonObjectRequest(Method.GET,
            url, null,
            new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG, "Error: " + error.getMessage());
                }
    });