ConnectivityManager connectivityManager;
NetworkInfo info;
connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
info = connectivityManager.getActiveNetworkInfo();if(info != null && info.isAvailable()) {
String name = info.getTypeName();
if(name.equals == ConnectivityManager.TYPE_WIFI) {
System.out.println("WIFI");
} else if(name.equals == ConnectivityManager.TYPE_MOBILE){
System.out.println("2G/3G");
}else{
}
} else {
System.out.println("没有可用网络");//doSomething()
}
参考:http://blog.csdn.net/chenzheng_java/article/details/6387116