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.google.zxing.client.android.history.HistoryActivity.java

public boolean netWorkdisponibilidade(Context cont) {
    boolean conectado = false;
    ConnectivityManager conmag;/*w w w.  java2 s  .  c o  m*/
    conmag = (ConnectivityManager) cont.getSystemService(Context.CONNECTIVITY_SERVICE);
    conmag.getActiveNetworkInfo();
    // Verifica o WIFI
    if (conmag.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
        conectado = true;
        Toast.makeText(this, R.string.toast_is_net_wifi, Toast.LENGTH_LONG).show();
    }
    // Verifica o 3G
    else if (conmag.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()) {
        conectado = true;
        Toast.makeText(this, R.string.toast_is_net_3g, Toast.LENGTH_LONG).show();
    } else {
        conectado = false;
    }
    return conectado;
}

From source file:eg.edu.alexu.alexandriauniversity.activity.ChannelsActivity.java

private void doFirstTime() {
    //add channels first run only
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean previouslyStarted = prefs.getBoolean(getString(R.string.pref_previously_started), false);
    if (!previouslyStarted) {

        //Check internet connection for now all times but next step will be first time only
        final ConnectivityManager connMgr = (ConnectivityManager) this
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (wifi.isAvailable() && wifi.isConnected()) {
            Toast.makeText(this, "Adding Feeds over WIFI", Toast.LENGTH_LONG).show();
            addChannelFirstTime();/*from   w w  w  .  j a  va  2s.  c  o m*/
            SharedPreferences.Editor edit = prefs.edit();
            edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE);
            edit.apply();
        } else if (mobile.isAvailable() && mobile.isConnected()) {
            Toast.makeText(this, "Adding Feeds Over Mobile 3G ", Toast.LENGTH_LONG).show();
            addChannelFirstTime();
            SharedPreferences.Editor edit = prefs.edit();
            edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE);
            edit.apply();
        } else {
            Toast.makeText(this, "No Network WIFI/3G, Can't Add Feeds!", Toast.LENGTH_LONG).show();
            SharedPreferences.Editor edit = prefs.edit();
            edit.putBoolean(getString(R.string.pref_previously_started), Boolean.FALSE);
            edit.apply();
        }
    }
}

From source file:com.g_node.gca.abstracts.AbstractContentTabFragment.java

private void getAndUpdateAbstractFiguresBtn() {
    String getFiguresQuery = "SELECT * FROM ABSTRACT_FIGURES WHERE ABSTRACT_UUID = '" + value + "';";
    Cursor absFiguresCursor = DatabaseHelper.database.rawQuery(getFiguresQuery, null);

    if (absFiguresCursor.getCount() > 0) {
        btnOpenAbstractFig.setText("Show Figures" + "  (" + absFiguresCursor.getCount() + ")");

        btnOpenAbstractFig.setOnClickListener(new OnClickListener() {

            @Override/*from w  w  w  .j  a  v a 2 s. co m*/
            public void onClick(View arg0) {
                //if Internet is connected
                if (isNetworkAvailable()) {

                    //check if interent is WIFI
                    ConnectivityManager connManager = (ConnectivityManager) getActivity()
                            .getSystemService(Context.CONNECTIVITY_SERVICE);
                    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                    NetworkInfo mMobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

                    if (mWifi.isConnected()) {
                        //Toast.makeText(getActivity(), "Connected via WLAN", Toast.LENGTH_SHORT).show();
                        Intent figuresIntent = new Intent(getActivity(), AbstractFiguresActivity.class);
                        figuresIntent.putExtra("abs_uuid", value);
                        startActivity(figuresIntent);

                    } else if (mMobile.isConnected()) {
                        //if connected with mobile data - 2G, 3G, 4G etc
                        //Toast.makeText(getActivity(), "Connected via Mobile Internet", Toast.LENGTH_SHORT).show();

                        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                        builder.setTitle("Additional Traffic Warning").setMessage(
                                "Downloading of Figures over Mobile Internet may create additional Traffic. Do you want to Continue ?")
                                .setPositiveButton("Continue", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        // if user Agrees to continue
                                        Intent figuresIntent = new Intent(getActivity(),
                                                AbstractFiguresActivity.class);
                                        figuresIntent.putExtra("abs_uuid", value);
                                        startActivity(figuresIntent);
                                    }
                                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        // Handle Cancel
                                        dialog.cancel();
                                    }
                                }).setIcon(android.R.drawable.ic_dialog_alert).show();

                    } else {
                        ;
                    } //end if/else of wlan/mobile

                } else {
                    Toast.makeText(getActivity(),
                            "Not Connected to Internet - Please connect to Internet first", Toast.LENGTH_SHORT)
                            .show();
                } //end if/else of isNetworkAvailable

            }
        });

    } else {
        btnOpenAbstractFig.setText("No Figures Found");
        btnOpenAbstractFig.setEnabled(false);
        //btnOpenAbstractFig.setVisibility(View.GONE);
    }
}

From source file:com.csipsimple.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);
    // }/* w ww.j a v a  2 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
                        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:com.snt.bt.recon.activities.MainActivity.java

public void syncServerDatabase() {
    //check for connectivity
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    //sync database
    if (isConnected) {
        boolean wifiOnly = sp.getBoolean("preferred_sync", false);
        boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
        if (!isWiFi && wifiOnly) {
            logDebug("syncServerDatabase",
                    "Phone isConnected - Not Synchronizing upon user request because connection is not WiFi");
        } else {/*  ww w .  j a  v a 2 s  .c  o  m*/
            logDebug("syncServerDatabase", "Phone isConnected - Synchronizing");

            syncSQLiteMySQLDB(Trip.class, "tripsJSON", "https://.../api/insert_trip.php");//TODO
            syncSQLiteMySQLDB(GPSLocation.class, "locationsJSON", "https://.../api/insert_locations.php");//TODO
            syncSQLiteMySQLDB(BluetoothClassicEntry.class, "bcJSON", "https://.../api/insert_bc.php");//TODO
            syncSQLiteMySQLDB(BluetoothLowEnergyEntry.class, "bleJSON", "https://.../api/insert_ble.php");//TODO
        }
    } else {
        logDebug("syncServerDatabase", "Phone isNotConnected");

    }
}

From source file:com.dmbstream.android.util.Util.java

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

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

    return connected && (!wifiRequired || wifiConnected);
}

From source file:org.computeforcancer.android.BOINCActivity.java

private void determineStatus() {
    try {//from   w ww. ja v a 2  s  . c o  m
        if (mIsBound) {
            ConnectivityManager conMngr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
            android.net.NetworkInfo wifi = conMngr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

            if (!wifi.isConnected()) {
                BOINCActivity.monitor.setAutostart(false);
                BOINCActivity.monitor.setRunMode(BOINCDefs.RUN_MODE_NEVER);
            } else {
                SharedPreferences mSharedPreferences = getApplicationContext().getSharedPreferences(
                        "org.computeforcancer.android", Context.MODE_PRIVATE | Context.MODE_MULTI_PROCESS);
                monitor.setAutostart(mSharedPreferences.getBoolean(SharedPrefs.AUTO_START, true));
                BOINCActivity.monitor.setRunMode(
                        mSharedPreferences.getBoolean(SharedPrefs.AUTO_START, true) ? BOINCDefs.RUN_MODE_AUTO
                                : BOINCDefs.RUN_MODE_NEVER);
            }
            Integer newComputingStatus = monitor.getComputingStatus();
            if (newComputingStatus != clientComputingStatus) {
                // computing status has changed, update and invalidate to force adaption of action items
                clientComputingStatus = newComputingStatus;
                supportInvalidateOptionsMenu();
            }
            /*
            if(numberProjectsInNavList != monitor.getProjects().size())
              numberProjectsInNavList = mDrawerListAdapter.compareAndAddProjects((ArrayList<Project>)monitor.getProjects());
            //setAppTitle();
            */}
    } catch (Exception e) {
    }
}

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

private void syncImages(SyncResult result, ConnectivityManager cm, PreferenceHelper preferenceHelper,
        SimpleArrayMap<String, String> woeidTimezones, SimpleArrayMap<String, WeatherData> previousData,
        WeatherData weatherData) throws VolleyError {

    NetworkInfo netInfo;//from   w  w w  .  j  a  v  a  2  s . co m
    String woeid = weatherData.woeid;
    WeatherData previous = previousData.get(woeid);
    File[] photos = mWeatherUtils.getCityPhotos(mContext, woeid);

    boolean changed = photos == null || previous == null
            || previous.nowConditionCode != weatherData.nowConditionCode;

    if (changed) {

        boolean downloadEnabled = preferenceHelper.getUseFlickrImages();
        boolean downloadOnWifiOnly = preferenceHelper.getDownloadImagesOnWifiOnly();
        boolean downloadWhenRoaming = preferenceHelper.getDownloadWhenRoaming();

        netInfo = cm.getActiveNetworkInfo();
        if (netInfo == null)
            return;
        boolean wifi = netInfo.getType() == ConnectivityManager.TYPE_WIFI;
        boolean roaming = netInfo.isRoaming();

        // tell the sync we got an io exception
        // so it knows we would like to try again later
        if (roaming && !downloadWhenRoaming) {
            result.stats.numIoExceptions++;
            return;
        }

        // well, we are not on wifi, and the user
        // only wants to sync this when wifi
        // is enabled.
        if (!wifi && downloadOnWifiOnly) {
            result.stats.numIoExceptions++;
            return;
        }

        // only download when the user has the option
        // to download flickr images enabled in
        // settings
        if (downloadEnabled) {
            String timezone = woeidTimezones.get(woeid);
            downloadWeatherImages(mContext, mBitmapUtils, woeid, weatherData, timezone);
            result.stats.numInserts++;
        }
    }
}

From source file:com.chalmers.schmaps.GoogleMapSearchLocation.java

/**
 * Check if the device is connected to internet.
 * Need three if-statements because getActiveNetworkInfo() may return null
 * and end up with a force close. So thats the last thing to check.
 * @return true if there is an internet connection
 *///from   w  ww  .j  a va2s . c o  m
public boolean gotInternetConnection() {
    ConnectivityManager cm = (ConnectivityManager) 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.connectsdk.discovery.DiscoveryManager.java

/**
 * Start scanning for devices on the local network.
 *//*from w w w  .j  ava2  s .  c om*/
public void start() {
    if (mSearching)
        return;

    if (discoveryProviders == null) {
        return;
    }

    mSearching = true;
    multicastLock.acquire();

    Util.runOnUI(new Runnable() {

        @Override
        public void run() {
            if (discoveryProviders.size() == 0) {
                registerDefaultDeviceTypes();
            }

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

            if (mWifi.isConnected()) {
                for (DiscoveryProvider provider : discoveryProviders) {
                    provider.start();
                }
            } else {
                Log.w("Connect SDK", "Wifi is not connected yet");

                Util.runOnUI(new Runnable() {

                    @Override
                    public void run() {
                        for (DiscoveryManagerListener listener : discoveryListeners)
                            listener.onDiscoveryFailed(DiscoveryManager.this,
                                    new ServiceCommandError(0, "No wifi connection", null));
                    }
                });
            }
        }
    });
}