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:io.github.hidroh.materialistic.AppUtils.java

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

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * Returns true if the network is available or about to become available.
 *//*from   w  w w .  j  a  va 2s . c o m*/
public static boolean isNetworkAvailable(Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);

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

}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

public static boolean isOnline(Context c) {
    ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting())
        return true;
    return false;
}

From source file:nu.yona.app.utils.AppUtils.java

/**
 * Check for network availability.//  w w  w  .  ja  va2  s.com
 *
 * @param context requested context object.
 * @return true if available else false.
 */
public static boolean isNetworkAvailable(final Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

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

From source file:org.fdroid.fdroid.UpdateService.java

/**
 * If we are to update the repos only on wifi, make sure that connection is active
 *//*from ww w .java 2s. c om*/
private static boolean isNetworkAvailableForUpdate(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    // this could be cellular or wifi
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork == null) {
        return false;
    }

    if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI && Preferences.get().isUpdateOnlyOnWifi()) {
        Log.i(TAG, "Skipping update - wifi not available");
        return false;
    }
    return activeNetwork.isConnectedOrConnecting();
}

From source file:free.yhc.netmbuddy.utils.Utils.java

/**
 * Is any available active network at this device?
 * @return/* w  ww  . j a  v  a  2s  .  co  m*/
 */
public static boolean isNetworkAvailable() {

    ConnectivityManager cm = (ConnectivityManager) getAppContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni;

    if (isPrefUseWifiOnly())
        ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    else
        ni = cm.getActiveNetworkInfo();

    if (null != ni)
        return ni.isConnectedOrConnecting();
    else
        return false;
}

From source file:org.eyeseetea.malariacare.network.ServerAPIController.java

/**
 * Returns true|false depending of the network connectivity.
 * @return/*from   ww w.j  a va2 s  . c  o m*/
 */
public static boolean isNetworkAvailable() {
    Context ctx = PreferencesState.getInstance().getContext();
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork == null) {
        return false;
    }
    return activeNetwork.isConnectedOrConnecting();
}

From source file:com.jtechme.apphub.UpdateService.java

/**
 * If we are to update the repos only on wifi, make sure that connection is active
 *//*from w w  w . j a  v  a  2 s  . c  o  m*/
public static boolean isNetworkAvailableForUpdate(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    // this could be cellular or wifi
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork == null)
        return false;

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI
            && prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) {
        Log.i(TAG, "Skipping update - wifi not available");
        return false;
    }
    return activeNetwork.isConnectedOrConnecting();
}

From source file:de.kirchnerei.bicycle.BicycleApplication.java

/**
 * Checks whether the network is online and a access to the internet is possible.
 *
 * @return true, when the access to internet is possible, otherwise it is false.
 *//*  w w  w. j a v  a  2s. c  o m*/
public boolean isNetworkOnline() {
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();
}

From source file:com.hctrom.romcontrol.AcercaDeFragment.java

/**
 * Comprueba si hay conexin a internet.// w w  w .  j  a  v  a2s.  com
 * @return boolean
 */
private boolean exiteConexionInternet() {
    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        return true;
    }
    return false;
}