Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 222
Vaibhav Avatar asked Sep 22 '11 08:09

Vaibhav


People also ask

How can I get connection type in Android?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken text view to show connection type.


2 Answers

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;
}
like image 99
DonGru Avatar answered Sep 30 '22 06:09

DonGru


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();}
      }
}
like image 39
Lalit Poptani Avatar answered Sep 30 '22 08:09

Lalit Poptani