首页 > 代码库 > 判断网络连接状态

判断网络连接状态

/**
* 判断网络连接状态
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cwjManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cwjManager.getActiveNetworkInfo();
if (info != null && info.isConnected()) {
CustomizedCustomToast.makeText(mContext, "Network Available",
Toast.LENGTH_LONG).show();
return true;
} else {
CustomizedCustomToast.makeText(mContext, "Network unAvailable",
Toast.LENGTH_LONG).show();
return false;
}
}

判断网络连接状态