Example usage for android.net NetworkInfo isConnected

List of usage examples for android.net NetworkInfo isConnected

Introduction

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

Prototype

@Deprecated
public boolean isConnected() 

Source Link

Document

Indicates whether network connectivity exists and it is possible to establish connections and pass data.

Usage

From source file:com.phonegap.NetworkManager.java

/**
 * Determine if a network connection exists.
 * //from   w  w  w.ja v a2s  .  c o  m
 * @return
 */
public boolean isAvailable() {
    NetworkInfo info = sockMan.getActiveNetworkInfo();
    boolean conn = false;
    if (info != null) {
        conn = info.isConnected();
    }
    return conn;
}

From source file:com.chess.genesis.net.SocketClient.java

public void logError(final Context context, final Exception trace, final JSONObject json) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo netInfo = cm.getActiveNetworkInfo();
    final FileLogger logger = new FileLogger(trace);

    logger.addItem("NetActive", (netInfo != null) ? netInfo.isConnected() : null);
    logger.addItem("isConnected", socket.isConnected());
    logger.addItem("isLoggedIn", isLoggedin);
    logger.addItem("loginHash", loginHash);
    logger.addItem("request", json.toString());
    logger.write();/*from www. j ava2 s  .  c o  m*/
}

From source file:ch.luethi.skylinestracker.PositionService.java

private void initConnectionStatus() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    app.online = activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:com.morxander.admin.finder.MainActivity.java

private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }// w  w w  .  ja v a  2  s .  co  m
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:ch.pec0ra.mobilityratecalculator.DistanceCalculator.java

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

From source file:com.raywenderlich.reposearch.MainActivity.java

private boolean isNetworkConnected() {
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); // 1
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); // 2
    return networkInfo != null && networkInfo.isConnected(); // 3
}

From source file:devbox.com.br.minercompanion.LoginActivity.java

public boolean isConnected() {
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    } else {// w  w w.j a  v  a2 s.  com
        Toast.makeText(this, "Sem acesso a internet", Toast.LENGTH_SHORT).show();
        return false;
    }
}

From source file:de.dhbw.organizer.calendar.backend.manager.NetworkManager.java

/**
 * tests if device got any internet connection
 * /*from  w ww.java 2  s .  c om*/
 * @return true if availabe, false otherwise
 */
public boolean isOnline() {
    boolean connected = false;
    try {
        connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        connected = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
        return connected;

    } catch (Exception e) {

        Log.e(TAG, "isOnline() ERROR " + e.toString());
    }
    return connected;
}

From source file:it.smartcampuslab.riciclo.geo.OSMGeocoder.java

private boolean isConnected() {
    NetworkInfo info = ((ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//from w  w  w. j  ava  2  s . c  o m
    return info != null && info.isConnected();
}

From source file:com.loadsensing.app.LoginActivity.java

private boolean checkConnection(Context ctx) {
    ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo i = conMgr.getActiveNetworkInfo();
    if (i == null)
        return false;
    if (!i.isConnected())
        return false;
    if (!i.isAvailable())
        return false;
    return true;// ww  w . j a  va  2 s.c o m
}