is Net Connected : Connectivity « Network « Android






is Net Connected

    
//package edu.scut.attmore.qsms.utils;

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

/**
 * @author Attmore
 * 
 */
class NetUtils {
  /**
   * check wheather connected
   * @param context
   * @return true connected false not connected
   */
  public static boolean isNetConnected(Context context) {
    try {
      ConnectivityManager connManger = (ConnectivityManager) context
          .getSystemService(Context.CONNECTIVITY_SERVICE);
      if(connManger!=null)
      {
        NetworkInfo netInfo=connManger.getActiveNetworkInfo();
        if(netInfo!=null&&netInfo.isConnected()){
          if(netInfo.getState()==NetworkInfo.State.CONNECTED){
            return true;
          }
        }
      }
      
    } catch (Exception e) {
      // TODO: handle exception
    }
    return false;
  }
}

   
    
    
    
  








Related examples in the same category

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