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 isNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = manager.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }//from   w  w w  .  ja  v  a 2  s.co m
    return false;
}

From source file:Main.java

public static boolean isWifi(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info == null)
        return false;

    int netType = info.getType();
    if (netType == ConnectivityManager.TYPE_WIFI) {
        return info.isConnected();
    } else {// w ww .  jav  a  2s  .  c  om
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    if (context != null) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        if (info != null) {
            return info.isAvailable();
        }//from   w  w  w  .  j  av a2s.c o  m
    }
    return false;
}

From source file:Main.java

public static boolean hasInternetConnection(final Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = conMan.getActiveNetworkInfo();
    if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }//from  w w w  . j  av  a 2s . c om
    return false;
}

From source file:Main.java

public static boolean isWifiConnect(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkINfo = cm.getActiveNetworkInfo();
    if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }//from   w w w.  ja va 2s . c  om
    return false;
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    return isConnected;
}

From source file:Main.java

/**
 * Determines if the network is currently available or not.
 * //from  ww w  .  j a v  a 2s .com
 * @param context The context with which to access the system connectivity service
 * @return True if the network is available, false if not
 */
public static boolean isNetworkAvailable(ContextWrapper context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo network = cm.getActiveNetworkInfo();
    return ((network != null) && (network.isConnected()));
}

From source file:Main.java

private static boolean isConnectionAvailable(Context context) {

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();

    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }/*from   w  w w  . j a  va2  s.co m*/
    return false;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cManager.getActiveNetworkInfo();
    if (info != null && info.isAvailable()) {
        return true;
    } else {/*from   ww  w. j av a  2s  .  co  m*/
        return false;
    }
}