Android Volley - Checking internet state

后端 未结 6 1857
耶瑟儿~
耶瑟儿~ 2020-12-08 08:30

Before I am using Volley, well as usual, I used AsyncTask to check my internet state.

Here is what I did in AsyncTask:

private class NetCheck extends         


        
6条回答
  •  庸人自扰
    2020-12-08 08:45

    new Response.ErrorListener() {
    
        @Override
        public void onErrorResponse(VolleyError volleyError) {
    
            if (volleyError instanceof TimeoutError || volleyError instanceof NoConnectionError) {
                Toast.makeText(getApplicationContext(), "No Connection/Communication Error!", Toast.LENGTH_SHORT).show();
    
            } else if (volleyError instanceof AuthFailureError) {
                Toast.makeText(getApplicationContext(), "Authentication/ Auth Error!", Toast.LENGTH_SHORT).show();
            } else if (volleyError instanceof ServerError) {
                Toast.makeText(getApplicationContext(), "Server Error!", Toast.LENGTH_SHORT).show();
            } else if (volleyError instanceof NetworkError) {
                Toast.makeText(getApplicationContext(), "Network Error!", Toast.LENGTH_SHORT).show();
            } else if (volleyError instanceof ParseError) {
                Toast.makeText(getApplicationContext(), "Parse Error!", Toast.LENGTH_SHORT).show();
            }
        }
    });
    

    This is good for you as a developer. But do not show some of this direct messages like auth and server-side error to the end user. Be creative and show something like can not connect at the moment.

提交回复
热议问题