How can I check using code whether the connection made is through Wifi or GSM/3G in android?
Asked
Active
Viewed 1,031 times
2 Answers
5
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;
}

Community
- 1
- 1

Muhammet Emre
- 349
- 3
- 17
0
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

sanjith kumar
- 325
- 2
- 3
- 13