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

private static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeInfo = connectivityManager.getActiveNetworkInfo();
    if (activeInfo != null && activeInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }/* www  . ja  va  2 s. c  o m*/
    return true;
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isWifi(Context context) {

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

    if (netInfo == null || !mConnectivity.getBackgroundDataSetting()) {
        return false;
    } else if (ConnectivityManager.TYPE_WIFI == netInfo.getType()) {
        return netInfo.isConnected();
    } else {//from   w  w  w .j a  v a  2 s . com
        return false;
    }

}

From source file:Main.java

public static boolean checkConnection(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        return networkInfo.isAvailable();
    }//from   w ww. j  ava2  s . c  o m
    return false;
}

From source file:Main.java

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

From source file:Main.java

public static int getConnectedType(Context context) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mNetworkInfo != null && mNetworkInfo.isAvailable()) {
        return mNetworkInfo.getType();
    }/*ww w .  j av  a 2  s  .c o m*/
    return -1;
}

From source file:Main.java

/**
 * Checks the devices connectivity/*ww  w.  j a v  a 2  s  . com*/
 * 
 * @return True if connection is available, false if not
 */
public static boolean isConnected(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo == null ? false : networkInfo.isAvailable();
}

From source file:Main.java

public static boolean networkUnreachable(Context cxt) {
    ConnectivityManager connectivityManager = (ConnectivityManager) cxt
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (null == activeNetworkInfo) {
        return true;
    }/*w ww. ja  va 2  s  .  co  m*/
    return !activeNetworkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
    if (mNetworkInfo != null) {
        return mNetworkInfo.isAvailable();
    }/*  w w  w.  j a v a 2  s.c o  m*/
    return false;
}