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:at.tugraz.ist.akm.networkInterface.WifiIpAddress.java

public String readLocalIpAddress() {

    NetworkInfo mobileNetInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mWifiManager.isWifiEnabled()) {
        return readWifiIP4Address();
    }//from w ww  .  j av  a 2 s  .co  m
    if (AppEnvironment.isRunningOnEmulator() && mobileNetInfo != null && mobileNetInfo.isConnected()) {
        try {
            return readIP4AddressOfEmulator();
        } catch (SocketException e) {
            mLog.error("not able to read local ip-address", e);
        }
    } else if (isWifiAPEnabled()) {
        return readIp4ApAddress();
    }

    mLog.error("failed to determine correct ip address");
    return null;
}

From source file:itesm.mx.golpedecalor.SelectGroupActivity.java

public void onClickSincronizar(View v) {
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mMobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mWifi.isConnected() || mMobile.isConnected()) {
        new RequestTask().execute("http://golpedecalor.comoj.com/dbHandler.php");
        Toast.makeText(getApplicationContext(), "Sincronizacion Exitosa", Toast.LENGTH_SHORT).show();
    } else {// w w w.  j  av  a 2s .  co m
        Toast.makeText(getApplicationContext(), "No hay conexin a internet", Toast.LENGTH_SHORT).show();
    }

}

From source file:github.daneren2005.dsub.util.Util.java

public static boolean isNetworkConnected(Context context, boolean streaming) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    boolean connected = networkInfo != null && networkInfo.isConnected();

    if (streaming) {
        boolean wifiConnected = connected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
        boolean wifiRequired = isWifiRequiredForDownload(context);

        return connected && (!wifiRequired || wifiConnected);
    } else {/*from   w w w.j  a  va  2s. com*/
        return connected;
    }
}

From source file:com.restswitch.controlpanel.MainActivity.java

public void onButtonClick(View v) {
    try {/*w ww  . j  av  a  2s. c om*/
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if ((networkInfo == null) || !networkInfo.isConnected()) {
            alertError("No network connection");
            return;
        }

        // get the device and io num
        int devnum = 0;
        int ionum = 0;
        try {
            String tag = (String) v.getTag();
            int val = Integer.parseInt(tag, 16);
            devnum = ((val >>> 4) & 0x0f);
            ionum = (val & 0x0f);
        } catch (Exception ex) {
            return;
        }
        //alertInfo("device num: " + devnum + "  io num: " + ionum);

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String pwdHash = prefs.getString("passwdHash", "");
        String devid = prefs.getString("devid" + devnum, "");
        String host = prefs.getString("host_name", "");

        String msg = ("[\"pulseRelay\"," + ionum + ",250]");
        sendDevice(devid, host, msg, pwdHash);
    } catch (Exception ex) {
        alertError(ex.getMessage());
    }
}

From source file:de.geeksfactory.opacclient.OpacClient.java

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

From source file:edgargtzg.popularmovies.DiscoverMoviesFragment.java

/**
 * Checks if there is any network available.
 * Based on a stackoverflow snippet./*ww w.ja  v a 2 s .com*/
 *
 * @return true if there is a network available, otherwise false.
 */
private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getActivity()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:com.finlay.geomonsters.MainActivity.java

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:com.trellmor.berrymotes.sync.EmoteDownloader.java

private void updateNetworkInfo() {
    synchronized (this) {
        ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();

        mIsConnected = networkInfo != null && networkInfo.isConnected();

        if (networkInfo != null) {
            mNetworkType = networkInfo.getType();
        } else {//from   w ww.  j  a v a  2  s.c  o m
            mNetworkType = Integer.MIN_VALUE;
        }
    }
}

From source file:yulei.android.client.AndroidMobilePushApp.java

public void myClickHandler(View view) {
    // Gets the URL from the UI's text field.
    String stringUrl = "http://localhost:8080/JavaSer2/HelloWorld"; //urlText.getText().toString();
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        new DownloadWebpageTask().execute(stringUrl);
    } else {/*w  w w .j av  a 2  s  .co  m*/
        //textView.setText("No network connection available.");
        Log.e("net", "No network connection available.");
    }
}

From source file:com.example.testplayer.NetworkManager.java

/**
 * Get the latest network connection information
 *
 * @param info the current active network info
 * @return a JSONObject that represents the network info
 *///from   w w  w  .ja va 2s . c om
private JSONObject getConnectionInfo(NetworkInfo info) {
    String type = TYPE_NONE;
    String extraInfo = "";
    if (info != null) {
        // If we are not connected to any network set type to none
        if (!info.isConnected()) {
            type = TYPE_NONE;
        } else {
            type = getType(info);
        }
        extraInfo = info.getExtraInfo();
    }

    Log.d("CordovaNetworkManager", "Connection Type: " + type);
    Log.d("CordovaNetworkManager", "Connection Extra Info: " + extraInfo);

    JSONObject connectionInfo = new JSONObject();

    try {
        connectionInfo.put("type", type);
        connectionInfo.put("extraInfo", extraInfo);
    } catch (JSONException e) {
    }

    return connectionInfo;
}