首页 > 代码库 > android判断网络是否可用

android判断网络是否可用

private boolean isNetworkConnected(Context context) {
    ConnectivityMannger cManager = (ConnectivityMannger)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nInfo = cManager.getActiveNetworkInfo();
    if(nInfo != null && nInfo.isAvailable()) {
        return nInfo.isConnected();
    }
    return false;
}

 

android判断网络是否可用