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

/**
 * Checks whether application has Internet connection.
 *//*from   w w w.  j a  va2 s . com*/
public static boolean isConnected(Activity a) {
    ConnectivityManager connMgr = (ConnectivityManager) a.getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected())
        return true;
    else
        return false;
}

From source file:Main.java

public static boolean isInternetConnected(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }/*from  w ww .ja  v  a 2  s  . c o  m*/
    return true;
}

From source file:Main.java

private static NetworkInfo getActiveNetworkInfo(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    return cm.getActiveNetworkInfo();
}

From source file:Main.java

public static boolean getNetStatus(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }//from  w  w  w. j  a v a2  s .  c o m
    return true;
}

From source file:Main.java

public static boolean isNetConnect(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    } else {/*from   w  ww . j  av  a2s.c o  m*/
        return false;
    }
}

From source file:Main.java

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

From source file:Main.java

static boolean isNetworkAvailable(Activity a) {
    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    // test for connection
    if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable()
            && cm.getActiveNetworkInfo().isConnected()) {
        return true;
    } else {//ww  w.  ja  v a 2  s. c om
        return false;
    }
}

From source file:Main.java

public static boolean isOpenNetwork(Activity activity) {
    ConnectivityManager connManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connManager.getActiveNetworkInfo() != null) {
        return connManager.getActiveNetworkInfo().isAvailable();
    }/*ww w . j  av  a 2s  .co  m*/
    return false;
}

From source file:Main.java

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

    int netType = info.getType();
    int netSubtype = info.getSubtype();
    if (netType == ConnectivityManager.TYPE_WIFI) {
        return info.isConnected();
    } else if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS) {
        return info.isConnected();
    } else {//from  w ww . jav  a 2 s.  c  o m
        return false;
    }
}

From source file:Main.java

/**
 * Check to see if the network is available.
 * @return true if there is access to the internet, false otherwise.
 *//* ww  w  .  j a  v a 2s .c  o  m*/
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    boolean isAvailable = false;
    if (info != null && info.isConnected()) {
        isAvailable = true;
    }
    Log.v("TheNetUtil", "isNetworkAvailable(). net is " + isAvailable);
    return isAvailable;
}