/**
* 获取当前网络类型
*
* @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络
*/
public static int getNetworkType() {
int netType = 0;
AppContext appContext = AppContextHolder.getAppContext();
ConnectivityManager connectivityManager = (ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
String extraInfo = networkInfo.getExtraInfo();
if (!Strings.isNullOrEmpty(extraInfo)) {
if (extraInfo.toLowerCase().equals("cmnet")) {
netType = NET_TYPE_NET;
} else {
netType = NET_TYPE_WAP;
}
}
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = NET_TYPE_WIFI;
}
return netType;
}