排球 - 错误的网址或网络连接错误?

时间:2015-03-24 19:22:15

标签: android connection android-volley

如何区分错误的URL(错误的服务器地址)和离线网络? 在这两种情况下,我都会收到VolleyError的通信,这是“instanceof NoConnectionError”和“instanceof NetworkError”

感谢

1 个答案:

答案 0 :(得分:0)

我终于通过问这个来解决它:

public static boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager = (ConnectivityManager)    
        mCtx.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfoconnectivityManager
                                                .getActiveNetworkInfo();
        return activeNetworkInfo != null &&  
        activeNetworkInfo.isConnected();
    }