Friday, September 14, 2012

Network Connection checking in Android

Hello Friend, its a simple code for check any type of network connection is available or not on your device.


  
public boolean isNetworkAvailable() {

              ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
              NetworkInfo networkInfo = cm.getActiveNetworkInfo();
              // if no network is available networkInfo will be null
              // otherwise check if we are connected
              if (networkInfo != null && networkInfo.isConnected()) {
                     Log.e("Network Testing", "***Available***");
                     return true;
              }
              Log.e("Network Testing", "***Not Available***");
              return false;
       }


No comments :

Post a Comment

Note: Only a member of this blog may post a comment.