2

How can I check using code whether the connection made is through Wifi or GSM/3G in android?

inforg
  • 749
  • 2
  • 8
  • 15

2 Answers2

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