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.abcvoipsip.ui.SipHome.java

private void asyncSanityCheck() {
    // if(Compatibility.isCompatible(9)) {
    // // We check now if something is wrong with the gingerbread dialer
    // integration
    // Compatibility.getDialerIntegrationState(SipHome.this);
    // }//from  ww w.  ja v a 2s  .  c  o m

    PackageInfo pinfo = PreferencesProviderWrapper.getCurrentPackageInfos(this);
    if (pinfo != null) {
        if (pinfo.applicationInfo.icon == R.drawable.ic_launcher_nightly) {
            Log.d(THIS_FILE, "Sanity check : we have a nightly build here");
            ConnectivityManager connectivityService = (ConnectivityManager) getSystemService(
                    CONNECTIVITY_SERVICE);
            NetworkInfo ni = connectivityService.getActiveNetworkInfo();
            // Only do the process if we are on wifi
            if (ni != null && ni.isConnected() && ni.getType() == ConnectivityManager.TYPE_WIFI) {
                // Only do the process if we didn't dismissed previously
                NightlyUpdater nu = new NightlyUpdater(this);

                if (!nu.ignoreCheckByUser()) {
                    long lastCheck = nu.lastCheck();
                    long current = System.currentTimeMillis();
                    long oneDay = 43200000; // 12 hours
                    if (current - oneDay > lastCheck) {
                        if (onForeground) {
                            // We have to check for an update
                            UpdaterPopupLauncher ru = nu.getUpdaterPopup(false);
                            if (ru != null && asyncSanityCheker != null) {
                                runOnUiThread(ru);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.aero2.android.DefaultActivities.SmogMapActivity.java

private boolean networkIsAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.FiskInfoUtility.java

public boolean isNetworkAvailable(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java

private boolean isInternetAvailable() {
    ConnectivityManager systemService = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:com.android.providers.downloads.DownloadInfo.java

/**
 * Returns whether this download is allowed to use the network.
 *//*from  www  . ja  va2s .co m*/
public NetworkState checkCanUseNetwork(long totalBytes) {
    final NetworkInfo info = mSystemFacade.getActiveNetworkInfo(mUid);
    if (info == null || !info.isConnected()) {
        return NetworkState.NO_CONNECTION;
    }
    if (DetailedState.BLOCKED.equals(info.getDetailedState())) {
        return NetworkState.BLOCKED;
    }
    if (mSystemFacade.isNetworkRoaming() && !isRoamingAllowed()) {
        return NetworkState.CANNOT_USE_ROAMING;
    }
    if (mSystemFacade.isActiveNetworkMetered() && !mAllowMetered) {
        return NetworkState.TYPE_DISALLOWED_BY_REQUESTOR;
    }
    return checkIsNetworkTypeAllowed(info.getType(), totalBytes);
}

From source file:de.mangelow.throughput.NotificationService.java

private boolean getNetworkState(int type) {
    ConnectivityManager connect = null;//from ww w. j  a v  a 2s .  c om
    connect = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connect != null) {
        NetworkInfo result = connect.getNetworkInfo(type);
        if (result != null && result.isConnected()) {
            return true;
        } else {
            return false;
        }
    } else
        return false;
}

From source file:com.appsimobile.appsii.module.weather.WeatherLoadingService.java

void doSync(String defaultUnit, String extraWoeid, SyncResult result) {

    if (defaultUnit == null)
        throw new IllegalArgumentException("defaultUnit == null");

    NetworkInfo netInfo = mConnectivityManager.getActiveNetworkInfo();

    boolean online = netInfo != null && netInfo.isConnected();

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "Handling sync");

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "Checking online");
    if (!online) {
        bailOut("No network connection");
        result.stats.numIoExceptions++;/*from   ww w .ja va 2  s  . com*/
        return;
    }
    boolean syncWhenRoaming = mPreferenceHelper.getSyncWhenRoaming();
    if (netInfo.isRoaming() && !syncWhenRoaming) {
        bailOut("Not syncing because of roaming connection");
        result.stats.numIoExceptions++;
        return;
    }

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- Checking online");

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "get woeids");
    String[] woeids = mConfigurationHelper.getWeatherWidgetWoeids(WeatherFragment.PREFERENCE_WEATHER_WOEID);
    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- get woeids");

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "extra woeids");
    if (extraWoeid != null) {
        int length = woeids.length;

        String[] temp = new String[length + 1];
        System.arraycopy(woeids, 0, temp, 0, length);
        temp[length] = extraWoeid;
        woeids = temp;
    }
    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- extra woeids");

    if (woeids.length == 0) {
        bailOut("Not syncing because there are no woeids");
        // tell the service to reschedule normally
        result.stats.numUpdates++;
        return;
    }

    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "find timezones");
    int N = woeids.length;
    SimpleArrayMap<String, String> woeidTimezones = new SimpleArrayMap<>(N);
    for (int i = 0; i < N; i++) {
        String woeid = woeids[i];
        long cellId = mConfigurationHelper.findCellWithPropertyValue(WeatherFragment.PREFERENCE_WEATHER_WOEID,
                woeid);
        if (cellId != -1) {
            String timezone = mConfigurationHelper.getProperty(cellId,
                    WeatherFragment.PREFERENCE_WEATHER_TIMEZONE, null);
            if (BuildConfig.DEBUG) {
                Log.d("WeatherLoadingService", "woeid -> timezone: " + woeid + " -> " + timezone);
            }
            woeidTimezones.put(woeid, timezone);
        }
    }
    if (BuildConfig.DEBUG)
        Log.d("WeatherLoadingService", "- find timezones");

    try {
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "request location");
        Location location;

        if (mPermissionUtils.holdsPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION)) {
            location = requestLocationInfoBlocking();
        } else {
            woeids = addFallbackWoeid(woeids, woeidTimezones);
            location = null;
        }
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "- request location");

        SimpleArrayMap<String, WeatherData> previousData = new SimpleArrayMap<>(woeids.length);
        for (String woeid : woeids) {
            WeatherData data = mWeatherUtils.getWeatherData(mContext, woeid);
            previousData.put(woeid, data);
        }

        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "load data");
        WeatherDataLoader loader = new WeatherDataLoader(location, woeids, defaultUnit);
        CircularArray<WeatherData> data = loader.queryWeather();
        result.stats.numUpdates++;
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "- load data");

        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "sync images");

        int size = data.size();
        for (int i = 0; i < size; i++) {
            WeatherData weatherData = data.get(i);
            try {
                syncImages(result, mConnectivityManager, mPreferenceHelper, woeidTimezones, previousData,
                        weatherData);
            } catch (VolleyError e) {
                Log.w("WeatherLoadingService", "error getting images", e);
            }
        }
        if (BuildConfig.DEBUG)
            Log.d("WeatherLoadingService", "- sync images");
    } catch (InterruptedException ignore) {
        // we have been requested to stop, so simply stop
        result.stats.numIoExceptions++;
    } catch (CantGetWeatherException e) {
        Log.e("WeatherLoadingService", "error loading weather. Waiting for next retry", e);
        result.stats.numIoExceptions++;
    }

}

From source file:mobile.tiis.appv2.LoginActivity.java

/**
 * function to check if there is an internet connectivity
 *///from   ww  w.ja  v a 2  s  .  com
public boolean isInternetAvailable() {
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null && wifiNetwork.isConnected()) {
        return true;
    }
    NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileNetwork != null && mobileNetwork.isConnected()) {
        return true;
    }
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {
        return true;
    }
    return false;
}

From source file:com.push.app.HomeActivity.java

/**
 * Check if we have a network connection
 * @return boolean/* w w w .j a  v a  2s.  c  o m*/
 */
boolean Online() {
    ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    // check that there is an active network
    if (info != null) {
        return info.isConnected();
    } else {
        return false;
    }
}

From source file:it.unime.mobility4ckan.MainActivity.java

private boolean isDeviceOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnected();
}