Checking the internet connection in android is either through Wifi or through GSM/3G?
How can I check using code whether the connection made is through Wifi or 开发者_运维百科GSM/3G in android?
From here: Detect network connection type on Android
// Only update if WiFi or 3G is connected and not roaming
int netType = info.getType();
int netSubtype = info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
return info.isConnected();
} else if (netType == ConnectivityManager.TYPE_MOBILE
&& netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
&& !mTelephony.isNetworkRoaming()) {
return info.isConnected();
} else {
return false;
}
Better yet, you can use TelephonyManager.
TelephonyManager tm = (TelephonyManager)
getSystemService(TELEPHONY_SERVICE);
String operatorname = tm.getNetworkOperatorName();
Please check this link http://developer.android.com/reference/android/telephony/TelephonyManager.html
精彩评论