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 cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isAvailable();
}

From source file:Main.java

public static boolean isNetworkAvailable(@Nonnull Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkAvailable(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 hasInternetAccess(Activity activity) {
    ConnectivityManager cm = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo() == null)
        return false;
    boolean ret = cm.getActiveNetworkInfo().isConnectedOrConnecting();
    return ret;//from w ww. jav  a  2 s  . co  m

}

From source file:Main.java

/**
 * Check WIFI connection.//from  w ww .j a  v  a 2  s .  c  o m
 *
 * @return
 */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return (info != null && ConnectivityManager.TYPE_WIFI == info.getType());
}

From source file:Main.java

public static Boolean isNetworkReachable(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo current = cm.getActiveNetworkInfo();
    if (current == null) {
        return false;
    }//w  w w . j  av a2s  .c  o m
    return (current.isAvailable());
}

From source file:Main.java

private static boolean isOnline(Context ctx) {
    final ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.isConnected();
}

From source file:Main.java

public static boolean isNetWorkConnected(Context context) {
    boolean result;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    result = netInfo != null && netInfo.isConnected();
    return result;
}

From source file:Main.java

public static NetworkInfo getNetworkInfo() {
    if (mAppContext == null)
        return null;
    ConnectivityManager cm = (ConnectivityManager) mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni;/*from  ww  w  .ja  v a2  s  . c o  m*/
}

From source file:Main.java

/**
 * Check if there is any connectivity to a Wifi network.
 * <p/>/*from   w w w .  j a  va2  s. c  o  m*/
 * Can be used in combination with {@link #isConnectedMobile}
 * to provide different features if the device is on a wifi network or a cell network.
 *
 * @param context The current Context or Activity that this method is called from
 * @return true if a wifi connection is available, otherwise false.
 */
public static boolean isConnectedWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);
}