ConnectivityManager conmanager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = conmanager.getActiveNetworkInfo();
if (activeNetworkInfo==null) {
//无网络状态
}else{
if (activeNetworkInfo.getType()==ConnectivityManager.TYPE_MOBILE) {
//有网络状态,并且为移动数据网络
}else if (activeNetworkInfo.getType()==ConnectivityManager.TYPE_WIFI) {
networkjude.Wifinetwork();
//有网络状态,且为WIFI状态
}
}
NetworkInfo activeNetworkInfo = conmanager.getActiveNetworkInfo();
if (activeNetworkInfo==null) {
//无网络状态
}else{
if (activeNetworkInfo.getType()==ConnectivityManager.TYPE_MOBILE) {
//有网络状态,并且为移动数据网络
}else if (activeNetworkInfo.getType()==ConnectivityManager.TYPE_WIFI) {
networkjude.Wifinetwork();
//有网络状态,且为WIFI状态
}
}