Example usage for android.net NetworkInfo isConnectedOrConnecting

List of usage examples for android.net NetworkInfo isConnectedOrConnecting

Introduction

In this page you can find the example usage for android.net NetworkInfo isConnectedOrConnecting.

Prototype

@Deprecated
public boolean isConnectedOrConnecting() 

Source Link

Document

Indicates whether network connectivity exists or is in the process of being established.

Usage

From source file:Main.java

public static boolean isWifiDataEnable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo == null)
        return false;

    return networkInfo.isConnectedOrConnecting();
}

From source file:eu.vranckaert.worktime.utils.network.NetworkUtil.java

/**
 * Checks if the device is connected with internet or not.
 * @param ctx The app-context./*from   ww  w  . j a v  a 2s. co  m*/
 * @return {@link Boolean#TRUE} if the device is connected or connecting, {@link Boolean#FALSE} if no connection is
 * available.
 */
public static boolean isOnline(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        Log.d(LOG_TAG, "Device is online");
        return true;
    }
    Log.d(LOG_TAG, "Device is not online");
    return false;
}

From source file:Main.java

public static boolean isMobileDataEnable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (networkInfo == null)
        return false;

    return networkInfo.isConnectedOrConnecting();
}

From source file:Main.java

public static boolean IsNetworkAvailable(Context context) {

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();
    if (connectivityManager != null && netInfo != null) {

        if (netInfo.isConnectedOrConnecting()) {
            return true;
        } else {/*from  w ww  . ja v a2s  .  c o m*/
            return false;
        }
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni == null) {
        // There are no active networks.
        return false;
    } else {/*from   w w  w  . jav  a2 s .  co m*/
        return ni.isConnectedOrConnecting();
    }
}

From source file:Main.java

public static boolean isWiFiOn(Context context) {
    NetworkInfo activeNetwork = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*from   w  ww . ja  v a2s.c  om*/
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting()
            && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isOnWiFi(Context context) {
    NetworkInfo activeNetwork = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*from w  w  w.j  av a2  s.c om*/

    return activeNetwork != null && activeNetwork.isConnectedOrConnecting()
            && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static String getcurrentNetworkNoWifi(Context context) {
    String network_type = "UNKNOWN";// maybe usb reverse tethering
    NetworkInfo active_network = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//from w w  w .  j av  a  2 s .c  om
    if (active_network != null && active_network.isConnectedOrConnecting()) {
        network_type = active_network.getSubtypeName();
    }
    return network_type;
}

From source file:Main.java

/**
 * Check if device currently is online.//w  w w.ja  v a2 s.  co  m
 *
 * @param context application context.
 * @return true if device is online.
 */
public static boolean isOnline(Context context) {
    final NetworkInfo networkInfo = ((ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnectedOrConnecting();
}

From source file:Main.java

/**
 * Used to determine if there is an active data connection and what type of
 * connection it is if there is one/*w ww. ja  va 2 s  .c o  m*/
 * 
 * @param context The {@link Context} to use
 * @return True if there is an active data connection, false otherwise.
 *         Also, if the user has checked to only download via Wi-Fi in the
 *         settings, the mobile data and other network connections aren't
 *         returned at all
 */
public static final boolean isOnline(final Context context) {
    /*
     * This sort of handles a sudden configuration change, but I think it
     * should be dealt with in a more professional way.
     */
    if (context == null) {
        return false;
    }

    boolean state = false;
    final boolean onlyOnWifi = false;// PreferenceUtils.getInstace(context).onlyOnWifi();

    /* Monitor network connections */
    final ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    /* Wi-Fi connection */
    final NetworkInfo wifiNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null) {
        state = wifiNetwork.isConnectedOrConnecting();
    }

    /* Mobile data connection */
    final NetworkInfo mbobileNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mbobileNetwork != null) {
        if (!onlyOnWifi) {
            state = mbobileNetwork.isConnectedOrConnecting();
        }
    }

    /* Other networks */
    final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    if (activeNetwork != null) {
        if (!onlyOnWifi) {
            state = activeNetwork.isConnectedOrConnecting();
        }
    }

    return state;
}