public static boolean checkNetWork(Context context) {
ConnectivityManager conn = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conn.getActiveNetworkInfo();
if (info == null || !conn.getBackgroundDataSetting()) {
return false;
}
// 判断网络连接类型,只有在2G/3G/wifi里进行一些数据更新。
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
return info.isConnected();
} else if (netSubtype == TelephonyManager.NETWORK_TYPE_GPRS
|| netSubtype == TelephonyManager.NETWORK_TYPE_CDMA
|| netSubtype == TelephonyManager.NETWORK_TYPE_EDGE) {
return false;
} else {
return true;
}
}
转载于:https://my.oschina.net/u/2273965/blog/364093