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:org.gluu.super_gluu.app.fragment.HomeFragment.java

private static boolean isConnected(final Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectivityManager != null) {
        NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();

        return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    }//from   w  w  w  .  j  a va  2  s.  c  om

    return false;
}

From source file:com.segment.analytics.internal.Utils.java

/**
 * Returns {@code true} if the phone is connected to a network, or if we don't have the enough
 * permissions. Returns {@code false} otherwise.
 *//*from www.j  a  v  a  2 s  . c  o m*/
public static boolean isConnected(Context context) {
    if (!hasPermission(context, ACCESS_NETWORK_STATE)) {
        return true; // assume we have the connection and try to upload
    }
    ConnectivityManager cm = getSystemService(context, CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:fr.shywim.antoinedaniel.utils.Utils.java

/**
 * Check if an internet connection is available
 *
 * @param context activity's context/*from ww  w  . java2  s  .  c  o m*/
 * @return true if a connection is available
 */
public static boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private static boolean checkConnection(Context context) {
    ConnectivityManager connectivityManager;
    NetworkInfo networkInfo;
    connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnectedOrConnecting();
}

From source file:org.gluu.super_gluu.app.MainActivityFragment.java

private static boolean isConnected(final Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    return isConnected;
}

From source file:com.andrew.apollo.utils.ApolloUtils.java

/**
 * Used to determine if there is an active data connection and what type of
 * connection it is if there is one//  w w  w. j av a 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 = 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;
}

From source file:li.barter.utils.Utils.java

/**
 * Reads the network info from service and sets up the singleton
 *///from   w  ww . j a  v  a 2 s. c  o m
public static void setupNetworkInfo(final Context context) {

    final ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = connManager.getActiveNetworkInfo();
    if (activeNetwork != null) {
        DeviceInfo.INSTANCE.setNetworkConnected(activeNetwork.isConnectedOrConnecting());
        DeviceInfo.INSTANCE.setCurrentNetworkType(activeNetwork.getType());
    } else {
        DeviceInfo.INSTANCE.setNetworkConnected(false);
        DeviceInfo.INSTANCE.setCurrentNetworkType(ConnectivityManager.TYPE_DUMMY);
    }

    Logger.d(TAG, "Network State Updated Connected: %b Type: %d", DeviceInfo.INSTANCE.isNetworkConnected(),
            DeviceInfo.INSTANCE.getCurrentNetworkType());
}

From source file:com.xiaomi.account.utils.SysHelper.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService("connectivity");
    if (cm == null) {
        return false;
    }// w  ww.java 2s  . c o m
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni == null || !ni.isConnectedOrConnecting()) {
        return false;
    }
    return true;
}

From source file:de.da_sense.moses.client.service.MosesService.java

/**
 * Checks if the device is connected to the Internet or it is being connected.
 * /*w w w.  j  a  v  a  2s.  c  o m*/
 * @return true if the device is connected or is being connected, false otherwise
 */
public static boolean isOnlineOrIsConnecting(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static boolean isOnWiFi(Context context) {
    NetworkInfo activeNetwork = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();/*from   ww w  . j a v  a2 s  .  co  m*/
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting()
            && activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
}