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:am.roadpolice.roadpolice.MainActivity.java

/**
 * This function checks if device is conneted to the network.
 *
 * @return True if connected; otherwise false.
 *//*from   w  w w.ja  va  2 s  . c  o  m*/
private boolean isConnected() {
    ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:xyz.bringoff.testtaskvkfriends_androidmiddle.util.ImageFetcher.java

/**
 * Simple network connection check./*  www .  j a  va 2s  . c om*/
 *
 * @param context
 */
private void checkConnection(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        Log.e(TAG, "checkConnection - no connection found");
    }
}

From source file:com.jcsoluciones.superdt.utilities.ImageFetcher.java

/**
* Simple network connection check.//from   ww  w  .ja  v  a2 s  .  co  m
*
* @param context
*/
private void checkConnection(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        Toast.makeText(context, "no  no connection found", Toast.LENGTH_LONG).show();
        Log.e(TAG, "checkConnection - no connection found");
    }
}

From source file:by.android.dailystatus.SettingsActivity.java

public boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        wasOffline = false;/*from   w w  w  .  j  av  a  2 s.c o  m*/
        return true;
    }
    return false;
}

From source file:com.gbozza.android.stockhawk.ui.StockFragment.java

/**
 * Utility method to check if the internet connection is available
 *
 * @return true or false/*from   w  w  w  . ja  va  2 s.c om*/
 */
private boolean networkUp() {
    ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnectedOrConnecting();
}

From source file:com.tangjd.displayingbitmaps.util.ImageFetcher.java

/**
* Simple network connection check.//w w  w. j  ava  2 s .  co m
*
* @param context
*/
private void checkConnection(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        Toast.makeText(context, "!", Toast.LENGTH_LONG).show();
        Log.e(TAG, "checkConnection - no connection found");
    }
}

From source file:com.xuwakao.mixture.framework.image.ImageFetcher.java

/**
 * Simple network connection check./*w  ww .  j a va 2 s  . c o  m*/
 *
 * @param context
 */
private void checkConnection(Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        Toast.makeText(context, R.string.no_network_connection_toast, Toast.LENGTH_LONG).show();
        MLog.error(TAG, "checkConnection - no connection found");
    }
}

From source file:com.zegoggles.smssync.service.ServiceBase.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isConnectedViaWifi_SDK21() {
    for (Network network : getConnectivityManager().getAllNetworks()) {
        final NetworkInfo networkInfo = getConnectivityManager().getNetworkInfo(network);
        if (networkInfo != null && networkInfo.getType() == TYPE_WIFI
                && networkInfo.isConnectedOrConnecting()) {
            return true;
        }//from   ww w  . j  a va  2  s .  c  o m
    }
    return false;
}

From source file:com.zegoggles.smssync.service.SmsBackupService.java

private void legacyCheckConnectivity() throws ConnectivityException {
    NetworkInfo active = getConnectivityManager().getActiveNetworkInfo();
    if (active == null || !active.isConnectedOrConnecting()) {
        throw new NoConnectionException();
    }// www  . j a v a  2 s  . com
    if (getPreferences().isWifiOnly() && isBackgroundTask() && !isConnectedViaWifi()) {
        throw new RequiresWifiException();
    }
}

From source file:foundme.uniroma2.it.professore.Connection.java

@Override
protected String[] doInBackground(String... params) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    if (!isConnected)
        return new String[] { Variables_it.NO_INTERNET };

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    for (int i = 1; i < params.length; i = i + 2) {
        nameValuePairs.add(new BasicNameValuePair(params[i], params[i + 1]));
    }// ww w  . ja v  a2  s . c  o m
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(params[0]);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        return new String[] { Variables_it.INVALID_IP };
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, Variables_it.ISO), 8);
        StringBuilder sb = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {
        return new String[] { Variables_it.FAIL_CONNECTION };
    }
    try {
        if (toDo.equalsIgnoreCase(Variables_it.GET)) {
            JSONObject json_data = new JSONObject(result);
            List<String> list = new ArrayList<String>();
            for (int i = 0;; i++) {
                try {
                    String n = json_data.getString(Integer.toString(i + 1));
                    list.add(n);
                } catch (JSONException e) {
                    break;
                }
            }
            String[] received = new String[list.size()];
            list.toArray(received);
            return received;
        } else if (returnMessage.equalsIgnoreCase(Variables_it.NAME)) {
            JSONObject json_data = new JSONObject(
                    result.substring(result.indexOf("{"), result.lastIndexOf("}") + 1));
            return new String[] { (json_data.getString(Variables_it.NAME)) };
        } else {
            JSONObject json_data = new JSONObject(
                    result.substring(result.indexOf("{"), result.lastIndexOf("}") + 1));
            code = (json_data.getInt(Variables_it.CODE));
        }
        if (code == 1) {
            return new String[] { returnMessage, params[params.length - 1] };
        } else {

            return new String[] { Variables_it.ERROR };
        }
    } catch (Exception e) {
        if (returnMessage.equalsIgnoreCase(Variables_it.NO_MSG)) {
            return new String[] { Variables_it.NO_MSG };
        }
        if (returnMessage.equalsIgnoreCase(Variables_it.NAME)) {
            return new String[] { Variables_it.ERROR };
        } else if (returnMessage.equalsIgnoreCase("")) {
            return new String[] { Variables_it.NO_COURSE };
        }
        return new String[] { Variables_it.JSON_FAILURE };
    }
}