How to check whether 3g is active or not in android
Asked Answered
S

5

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:)

Sheryl answered 22/9, 2011 at 8:7 Comment(0)
D
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;
}
Drum answered 22/9, 2011 at 10:40 Comment(0)
C
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();}
      }
}
Currey answered 22/9, 2011 at 8:27 Comment(0)
C
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;
Ceceliacecil answered 22/9, 2011 at 8:19 Comment(0)
Z
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!

Zephyrus answered 22/9, 2011 at 8:16 Comment(0)
L
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;
}
Loesch answered 22/9, 2011 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.