is Network Available : Connectivity « Network « Android






is Network Available

    

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

class CnbetaUtil {

  public static boolean isNetworkAvailable(Activity mActivity) {
    Context context = mActivity.getApplicationContext();
    ConnectivityManager connectivity = (ConnectivityManager) context
        .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
      return false;
    } else {
      NetworkInfo[] info = connectivity.getAllNetworkInfo();
      if (info != null) {
        for (int i = 0; i < info.length; i++) {
          if (info[i].getState() == NetworkInfo.State.CONNECTED) {
            return true;
          }
        }
      }
    }
    return false;
  }

}

   
    
    
    
  








Related examples in the same category

1.System InetAddress
2.is Net Connected
3.Connectivity Tester
4.Is Android connected to your server
5.Is connected
6.Is Connected To Internet