Example usage for android.net ConnectivityManager TYPE_WIFI

List of usage examples for android.net ConnectivityManager TYPE_WIFI

Introduction

In this page you can find the example usage for android.net ConnectivityManager TYPE_WIFI.

Prototype

int TYPE_WIFI

To view the source code for android.net ConnectivityManager TYPE_WIFI.

Click Source Link

Document

A WIFI data connection.

Usage

From source file:com.theonespy.util.Util.java

public static boolean syncMethodOk() {
    if (Util.getSyncMethod().equals(Util.SYNC_METHOD_OFF)) {
        return false;
    } else if (Util.getSyncMethod().equals(Util.SYNC_METHOD_WIFI)) {
        ConnectivityManager connManager = (ConnectivityManager) MyApplication.getAppContext()
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        return connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
    } else {//from ww w  .  ja va2  s.  c  o m
        return true;
    }
}

From source file:com.iStudy.Study.Renren.Util.java

/**
 * ??/*w  w  w  .ja v a  2  s.c om*/
 * @param
 *       Context
 * @return 
 *       true - ?3G/GSM?wifi
 *       false - ?contextnull
 */
public static boolean isNetworkConnected(Context context) {
    if (context == null) {
        return false;
    }
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    State mobileState = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    State wifiState = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (mobileState == State.DISCONNECTED && wifiState == State.DISCONNECTED) {
        return false;
    }
    return true;
}

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  w  w w  .ja v a2s .co  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.cybrosys.currency.CurrencyMain.java

public final boolean isConnection() {
    @SuppressWarnings("static-access")
    ConnectivityManager cm = (ConnectivityManager) getActivity()
            .getSystemService(getActivity().CONNECTIVITY_SERVICE);

    NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null && wifiNetwork.isConnected()) {
        return true;
    }//from   w ww.j a va2s  .co  m
    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.smedic.tubtub.BackgroundAudioService.java

/**
 * Get the best available audio stream given connection type.
 * If the user is on wifi, then provide the best quality audio from video sources, if available.
 * Otherwise, use DASH audio streams to save on mobile data.
 *
 * @TODO make source configurable by the user.
 *
 * @param ytFiles Array of available streams
 * @return Audio stream with highest bitrate
 *//* w  w w.j a v  a2 s  .co  m*/
@Nullable
private YtFile findBestStream(SparseArray<YtFile> ytFiles) {
    final long start = System.nanoTime();

    final int[] mobileAllowed = { 251, 140, 171, 18, 250, 249, 36, 17 };
    final int[] wifiAllowed = { 22, 251, 140, 171, 43, 18, 250, 249, 36, 17 };

    final int[] allowedItags = network.networkType() == ConnectivityManager.TYPE_WIFI ? wifiAllowed
            : mobileAllowed;

    for (int itag : allowedItags) {
        final YtFile ytFile = ytFiles.get(itag);
        if (ytFile != null) {
            final long end = System.nanoTime();
            final long cost = end - start;
            Log.i(TAG, "Found best stream with itag " + ytFile.getFormat().getItag() + " in " + cost / 1000000.0
                    + "ms.");

            return ytFile;
        }
    }

    Log.e(TAG, "Unable to find audio stream from available candidates.");
    return null;
}

From source file:com.sip.pwc.sipphone.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 . j  a v  a2  s . com

    // Nightly build check
    if (NightlyUpdater.isNightlyBuild(this)) {
        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
                        NightlyUpdater.UpdaterPopupLauncher ru = nu.getUpdaterPopup(false);
                        if (ru != null && asyncSanityChecker != null) {
                            runOnUiThread(ru);
                        }
                    }
                }
            }
        }
    }

    applyWarning(WarningUtils.WARNING_PRIVILEGED_INTENT,
            WarningUtils.shouldWarnPrivilegedIntent(this, prefProviderWrapper));
    applyWarning(WarningUtils.WARNING_NO_STUN, WarningUtils.shouldWarnNoStun(prefProviderWrapper));
    applyWarning(WarningUtils.WARNING_VPN_ICS, WarningUtils.shouldWarnVpnIcs(prefProviderWrapper));
    applyWarning(WarningUtils.WARNING_SDCARD, WarningUtils.shouldWarnSDCard(this, prefProviderWrapper));
}

From source file:org.qeo.android.service.QeoService.java

private void configureNetworkSettings(NetworkInfo activeNetworkInfo) {
    if (activeNetworkInfo != null) {
        switch (activeNetworkInfo.getType()) {
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_WIFI:
            // only enable UDP on WIFI or ETHERNET
            LOG.fine("enable UDP");
            NativeQeo.setUdpMode(true);/*from   w  w  w  .  j  av a  2  s  .c o m*/
            break;
        default:
            // disable UDP
            LOG.fine("disable UDP");
            NativeQeo.setUdpMode(false);
            break;
        }
    }
}

From source file:com.yozio.android.YozioHelper.java

/**
 * Gets the connection type used by this device ("mobile" or "wifi").
 *
 * @return Connection type the device is using.
 *//*from w  ww.j a  va2 s.  c om*/
private void setConnectionType() {
    try {
        // Get connection type
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivityManager != null && connectivityManager.getActiveNetworkInfo() != null) {
            switch (connectivityManager.getActiveNetworkInfo().getType()) {
            case ConnectivityManager.TYPE_WIFI:
            case 0x6: // ConnectivityManager.TYPE_WIMAX
                connectionType = "wifi";
                break;
            default:
                connectionType = "mobile";
                break;
            }
        }
    } catch (Exception e) {
    }
}

From source file:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java

private void setupWifiBroadcast() {
    broadcastReceiver = new WifiBroadcastReceiver(ShowModuleActivity.this);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    registerReceiver(broadcastReceiver, intentFilter);

    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    // initialize wifi connection state
    if (mWifi != null && mWifi.isConnected()) {
        wifiConnected = true;//from ww w .j a v a 2 s  .  c  o  m
    }
}