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:com.ilearnrw.reader.utils.HttpHelper.java

public static boolean isNetworkAvailable(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return (ni != null) && (ni.isConnected());
}

From source file:jp.co.conit.sss.sp.ex1.util.HttpUtil.java

/**
 * ???????// ww  w . j a  v  a 2  s.co  m
 * 
 * @param context {@code null}???
 * @return {@code true}:??{@code false}:??
 */
public static boolean isConnected(Context context) {

    if (context == null) {
        throw new IllegalArgumentException("'context' must not be null.");
    }

    boolean isConnectied = false;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Service.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
    if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
        isConnectied = true;
    }
    return isConnectied;
}

From source file:Main.java

public static boolean checkGprsNetwork(Context context) {
    boolean has = false;
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    NetworkInfo info = connectivity.getActiveNetworkInfo();
    int netType = info.getType();
    int netSubtype = info.getSubtype();
    if (netType == ConnectivityManager.TYPE_MOBILE && netSubtype == TelephonyManager.NETWORK_TYPE_UMTS
            && !mTelephony.isNetworkRoaming()) {
        has = info.isConnected();/* w ww  .ja  v a  2s . co  m*/
    }
    return has;

}

From source file:com.android.utility.util.Network.java

/**
 * Check if data connection is available.
 * /*w ww .j a v  a 2  s.co  m*/
 * @param context
 * @return
 */
public static boolean isDataConnectionAvailable(Context context) {
    if (context == null) {
        throw new IllegalArgumentException();
    }

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    return ((netInfo != null) && netInfo.isConnected());
}

From source file:Main.java

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

        if (networkinfo.getState() == NetworkInfo.State.CONNECTED) {
            return true;
        } else {
            return false;
        }
    }
    return false;
}

From source file:Main.java

/**
 * Get network type/*from   w w w  .  jav a  2  s .com*/
 *
 * @param context
 * @return boolean
 */
public static int getNetworkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo();
    return networkInfo == null ? -1 : networkInfo.getType();
}

From source file:com.mytwitter.Network.NetworkHelper.java

/**
 * Checks whether some network is connected and fully usable.
 *//*  w w  w .j  av  a  2 s  .c  o m*/
public static boolean connectedToNetwork(ConnectivityManager connectivityManager) {
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    return (activeNetwork != null && activeNetwork.isConnectedOrConnecting());
}

From source file:net.line2soft.preambul.utils.Network.java

/**
 * Checks if a network is available./*from  w  ww . j  a  v a2  s . c o  m*/
 * @param ct An application context
 * @return True if a network is available, false else
 */
public static boolean checkAvailableNetwork(Context ct) {
    boolean result = false;
    ConnectivityManager cm = (ConnectivityManager) ct.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {
        result = true;
    }
    return result;
}

From source file:Main.java

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

From source file:Main.java

public static boolean isConnect(Context context) {

    ConnectivityManager mConnectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
    // check if connect
    NetworkInfo netInfo = mConnectivity.getActiveNetworkInfo();
    if (netInfo == null || !mConnectivity.getBackgroundDataSetting()) {
        return false;
    } else {//from www. ja va2s  .co  m
        return true;
    }
}