Example usage for android.net ConnectivityManager getActiveNetworkInfo

List of usage examples for android.net ConnectivityManager getActiveNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getActiveNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getActiveNetworkInfo() 

Source Link

Document

Returns details about the currently active default data network.

Usage

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager cnm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cnm.getActiveNetworkInfo();
    return ni != null && ni.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isNetworkAvailable(Activity a) {
    ConnectivityManager connectivityManager = (ConnectivityManager) a.getSystemService(a.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }/*www  .j  a va  2  s . c om*/
    return true;
}

From source file:Main.java

public static boolean CheckNetwork(Context context) {
    boolean bool = false;
    ConnectivityManager localConnectivityManager = (ConnectivityManager) context
            .getSystemService("connectivity");
    if (localConnectivityManager.getActiveNetworkInfo() != null)
        bool = localConnectivityManager.getActiveNetworkInfo().isAvailable();
    return bool;// ww w.  j a  va  2s  . c o  m
}

From source file:Main.java

public static boolean isNetworkEnabled(Context pContext) {
    boolean vResult = false;
    ConnectivityManager cm = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo vNetworkInfo = cm.getActiveNetworkInfo();
    if (vNetworkInfo != null) {
        vResult = vNetworkInfo.isConnectedOrConnecting();
    }// w  w  w  .j a  v  a  2 s  .co m
    return vResult;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getBackgroundDataSetting() && cm.getActiveNetworkInfo() != null;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null || networkInfo.isConnected() == false) {
        return false;
    }//from  w  w w.  jav a 2 s  .  c o  m
    return true;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        return false;
    } else {/*from  www . j  av a  2s . co m*/
        return true;
    }
}

From source file:Main.java

/**
 * This checks the system-side for network connectivity, then pings the google
 * server to make sure they have internet connection. One other method avail here for use
 * in checking via ConnectivityManager.//ww  w.j  a va 2s.c  om
 * @param context Context to be passed
 * @return Returns a boolean, true if they have internet, false if they do not.
 */
public static boolean haveNetworkConnection3(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean checkNetwork(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo != null) {
        if (networkInfo.isConnected()) {
            return true;
        }//from w w  w.  jav a  2s  .co m
    }
    return false;
}