5

i am trying to check whether 3G is active or not in my handset and after that i have to fire an Intent. So plz anybody help me out Thanks in advance:)

Vaibhav
  • 123
  • 1
  • 6

5 Answers5

5

another snippet from an applilcation I've written recently:

TelephonyManager telManager;    
telManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
int cType = telManager.getNetworkType();
String cTypeString;
switch (cType) {
        case 1: cTypeString = "GPRS"; break;
        case 2: cTypeString = "EDGE"; break;
        case 3: cTypeString = "UMTS"; break;
        case 8: cTypeString = "HSDPA"; break;
        case 9: cTypeString = "HSUPA"; break;
        case 10:cTypeString = "HSPA"; break;
        default:cTypeString = "unknown"; break;
}
DonGru
  • 13,532
  • 8
  • 45
  • 55
3

Try this stuff,

    void checkConnectionStatus()
      {
       ConnectivityManager connMgr = (ConnectivityManager)
      this.getSystemService(Context.CONNECTIVITY_SERVICE);


      final android.net.NetworkInfo wifi =
      connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);


      final android.net.NetworkInfo mobile =
      connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


      if( wifi.isAvailable() ){
      Toast.makeText(this, "Wifi" , Toast.LENGTH_LONG).show();
      }
      else if( mobile.isAvailable() ){
      Toast.makeText(this, "Mobile 3G " , Toast.LENGTH_LONG).show();
      }
      else
      {Toast.makeText(this, "No Network " , Toast.LENGTH_LONG).show();}
      }
}
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
2

first you need to check if is wifi or mobile network

than just call

(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getNetworkType());

not that you could be on EDGE or GPRS or something so you can also do this

if (getSsTelephony().getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS)
    return NETWORK_3G;
Lukap
  • 31,523
  • 64
  • 157
  • 244
1
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);

    NetworkInfo mMobile = connManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mMobile.isAvailable() == true) {
        Intent otherActivity = new Intent();
        mapActivity.setClass(getBaseContext(), other.class);
        startActivity(otherActivity);
    }

Don't forget to add the "ACCESS_NETWORK_STATE" permission in the AndroidManifext.xml file!

Saqib Razaq
  • 864
  • 1
  • 7
  • 13
0

This will check if you have internet connection(3G):

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager
            .getActiveNetworkInfo();
    return activeNetworkInfo != null;
}
Gaurav
  • 1,700
  • 4
  • 22
  • 38