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:)
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.
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;
}
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();}
      }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With