List of usage examples for android.net ConnectivityManager TYPE_WIFI
int TYPE_WIFI
To view the source code for android.net ConnectivityManager TYPE_WIFI.
Click Source Link
From source file:de.teambluebaer.patientix.activities.LoginActivity.java
/** * On press of the "Login" button, the users can access to the APP * with their PIN and after the StartActivity will be loaded. * * @param v default parameter to change something of the view *//*w w w . j a v a2 s .c om*/ public void onClickLoginButton(View v) { ConnectivityManager connManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE); NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (mWifi.isConnected()) { if (passwordHash(editTextPassword.getText().toString()).equals(Constants.PIN)) { new GetTabletID().execute(); } else { editTextPassword.setText(""); Toast.makeText(this, "Falscher PIN!!!", Toast.LENGTH_LONG).show(); } } else { editTextPassword.setText(""); Toast.makeText(this, "WiFi ist abgeschaltet, bitte schalten sie das WiFi wieder ein.", Toast.LENGTH_LONG).show(); } }
From source file:com.android.settings.cyanogenmod.LtoService.java
private boolean shouldDownload() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { if (ALOGV) Log.v(TAG, "No network connection is available for LTO download"); } else {//from w w w . j a v a 2s. c o m boolean wifiOnly = prefs.getBoolean(LocationSettings.KEY_GPS_DOWNLOAD_DATA_WIFI_ONLY, true); if (wifiOnly && info.getType() != ConnectivityManager.TYPE_WIFI) { if (ALOGV) { Log.v(TAG, "Active network is of type " + info.getTypeName() + ", but Wifi only was selected"); } return false; } } long now = System.currentTimeMillis(); long lastDownload = getLastDownload(); long due = lastDownload + LongTermOrbits.getDownloadInterval(); if (ALOGV) { Log.v(TAG, "Now " + now + " due " + due + "(" + new Date(due) + ")"); } if (lastDownload != 0 && now < due) { if (ALOGV) Log.v(TAG, "LTO download is not due yet"); return false; } return true; }
From source file:com.quuzz.tbg.recyclerview.MainActivity.java
/** * Check whether the device is connected, and if so, whether the connection * is wifi or mobile (it could be something else). *//*from w w w . j a v a 2 s . com*/ private void checkNetworkConnection() { ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeInfo = connMgr.getActiveNetworkInfo(); if (activeInfo != null && activeInfo.isConnected()) { wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI; mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE; if (wifiConnected) { Log.i(TAG, "wifi connected"); } else if (mobileConnected) { Log.i(TAG, "mobile connected"); } } else { Log.i(TAG, "no internet connections"); } }
From source file:org.smap.smapTask.android.receivers.NetworkReceiver.java
private boolean interfaceIsEnabled(Context context, NetworkInfo currentNetworkInfo) { // make sure autosend is enabled on the given connected interface SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sendwifi = sharedPreferences.getBoolean(PreferencesActivity.KEY_AUTOSEND_WIFI, false); boolean sendnetwork = sharedPreferences.getBoolean(PreferencesActivity.KEY_AUTOSEND_NETWORK, false); return (currentNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI && sendwifi || currentNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE && sendnetwork); }
From source file:android_network.hetnet.vpn_service.Util.java
public static boolean isWifiActive(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); return (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI); }
From source file:org.flakor.androidtool.utils.HttpUtil.java
public int checkNetworkState() { int state = NONE_NET; ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); State mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); // 3G?wifi?2G?????? if (mobile == State.CONNECTED || mobile == State.CONNECTING) { state = MOBILE_NET;/*from w w w . j a v a 2s .com*/ } if (wifi == State.CONNECTED || wifi == State.CONNECTING) { state = WIFI_NET; } return state; }
From source file:com.example.testapplication.DialogLocation.java
@SuppressLint("InlinedApi") @Override/*from w ww .j a v a 2 s .co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { mProgressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge); mProgressBarInv = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge); mProgressBarInv.setVisibility(ProgressBar.GONE); mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); mCriteria = new Criteria(); int criteria = (mGpsPref) ? Criteria.POWER_HIGH : Criteria.POWER_MEDIUM; mCriteria.setPowerRequirement(criteria); mProvider = mLocationManager.getBestProvider(mCriteria, true); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); int telephonyInfo = tm.getNetworkType(); boolean networkAvailable = true; if ((telephonyInfo == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected()) || !mLocationManager.isProviderEnabled("network")) { networkAvailable = false; } int locationMode = -1; int locationType = -1; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { locationMode = Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (SettingNotFoundException e) { e.printStackTrace(); } if (locationMode == Settings.Secure.LOCATION_MODE_OFF || (!networkAvailable && (mProvider.matches("network")))) locationType = NO_LOCATION_SERVICES; else if (mGpsPref && (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY)) locationType = (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || !networkAvailable) ? USING_ONLY_GPS_LOCATION : USING_GPS_LOCATION_NETWORK_AVAILABLE; else if (mProvider.matches("network") && (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY)) locationType = USING_NETWORK_LOCATION; } else { if (mProvider.matches("passive") || !networkAvailable && (mProvider.matches("network") || (!mGpsPref && mProvider.matches("gps")))) locationType = NO_LOCATION_SERVICES; else if (mProvider.matches("gps") && mGpsPref) locationType = ((mProvider.matches("gps")) || !networkAvailable) ? USING_ONLY_GPS_LOCATION : USING_GPS_LOCATION_NETWORK_AVAILABLE; else if (mProvider.matches("network")) locationType = USING_NETWORK_LOCATION; } switch (locationType) { case NO_LOCATION_SERVICES: builder.setTitle(DIALOG_LOCATION_NO_LOCATION_SERVICES_TITLE); builder.setMessage(DIALOG_LOCATION_NO_LOCATION_SERVICES_MESSAGE); builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton); mAbortRequest = true; break; case USING_ONLY_GPS_LOCATION: builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE); builder.setMessage(DIALOG_LOCATION_ONLY_GPS_MESSAGE); builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton); builder.setView(mProgressBar); break; case USING_GPS_LOCATION_NETWORK_AVAILABLE: builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE); builder.setPositiveButton(DIALOG_LOCATION_USE_NETWORK, null); builder.setView(mProgressBar); break; case USING_NETWORK_LOCATION: builder.setView(mProgressBar); builder.setTitle(DIALOG_LOCATION_UPDATING_NETWORK_TITLE); break; } builder.setNegativeButton(DIALOG_LOCATION_CANCEL, cancelListener); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { mCallback.onLocationFound(null, mFragmentId); mLocationManager.removeUpdates(DialogLocation.this); Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show(); dialog.cancel(); return true; } return false; } }); mRealDialog = builder.create(); mRealDialog.setOnShowListener(usingNetwork); mRealDialog.setCanceledOnTouchOutside(false); return mRealDialog; }
From source file:com.raywenderlich.reposearch.MainActivity.java
private boolean isWifiConnected() { ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); return networkInfo != null && (ConnectivityManager.TYPE_WIFI == networkInfo.getType()) && networkInfo.isConnected(); }
From source file:org.basdroid.common.NetworkUtils.java
public static boolean isLTE(Context context) { NetworkInfo info = getNetworkInfo(context); if (info == null || !info.isConnected()) { return false; }// ww w.j a v a2 s .co m int type = info.getType(); int subType = info.getSubtype(); if (type == ConnectivityManager.TYPE_WIFI) { return false; } else if (type == ConnectivityManager.TYPE_MOBILE) { switch (subType) { case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_UMTS: return false; // ~ 50-100 kbps /* * Above API level 7, make sure to set android:targetSdkVersion * to appropriate level to use these */ case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11 case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9 case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13 case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8 return false; // ~ 50-100 kbps case TelephonyManager.NETWORK_TYPE_LTE: // API level 11 return true; // ~ 10+ Mbps // Unknown case TelephonyManager.NETWORK_TYPE_UNKNOWN: default: return false; } } else { return false; } }
From source file:ch.ethz.coss.nervousnet.vm.sensors.ConnectivitySensor.java
public void runConnectivitySensor() { Log.d(LOG_TAG, "Inside runConnectivitySensor"); if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return;// w w w. j av a2 s . com } ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); int networkType = -1; boolean isRoaming = false; if (isConnected) { networkType = activeNetwork.getType(); isRoaming = activeNetwork.isRoaming(); } String wifiHashId = ""; int wifiStrength = Integer.MIN_VALUE; if (networkType == ConnectivityManager.TYPE_WIFI) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); StringBuilder wifiInfoBuilder = new StringBuilder(); wifiInfoBuilder.append(wi.getBSSID()); wifiInfoBuilder.append(wi.getSSID()); try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.update(wifiInfoBuilder.toString().getBytes()); wifiHashId = new String(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { } wifiStrength = wi.getRssi(); } byte[] cdmaHashId = new byte[32]; byte[] lteHashId = new byte[32]; byte[] gsmHashId = new byte[32]; byte[] wcdmaHashId = new byte[32]; TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); List<CellInfo> cis = tm.getAllCellInfo(); if (cis != null) { // New method for (CellInfo ci : cis) { if (ci.isRegistered()) { if (ci instanceof CellInfoCdma) { CellInfoCdma cic = (CellInfoCdma) ci; cdmaHashId = generateMobileDigestId(cic.getCellIdentity().getSystemId(), cic.getCellIdentity().getNetworkId(), cic.getCellIdentity().getBasestationId()); } if (ci instanceof CellInfoGsm) { CellInfoGsm cic = (CellInfoGsm) ci; gsmHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(), cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCid()); } if (ci instanceof CellInfoLte) { CellInfoLte cic = (CellInfoLte) ci; lteHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(), cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCi()); } if (ci instanceof CellInfoWcdma) { CellInfoWcdma cic = (CellInfoWcdma) ci; wcdmaHashId = generateMobileDigestId(cic.getCellIdentity().getMcc(), cic.getCellIdentity().getMnc(), cic.getCellIdentity().getCid()); } } } } else { // Legacy method CellLocation cl = tm.getCellLocation(); if (cl instanceof CdmaCellLocation) { CdmaCellLocation cic = (CdmaCellLocation) cl; cdmaHashId = generateMobileDigestId(cic.getSystemId(), cic.getNetworkId(), cic.getBaseStationId()); } if (cl instanceof GsmCellLocation) { GsmCellLocation cic = (GsmCellLocation) cl; gsmHashId = generateMobileDigestId(cic.getLac(), 0, cic.getCid()); } } StringBuilder mobileHashBuilder = new StringBuilder(); mobileHashBuilder.append(new String(cdmaHashId)); mobileHashBuilder.append(new String(lteHashId)); mobileHashBuilder.append(new String(gsmHashId)); mobileHashBuilder.append(new String(wcdmaHashId)); dataReady(new ConnectivityReading(System.currentTimeMillis(), isConnected, networkType, isRoaming, wifiHashId, wifiStrength, mobileHashBuilder.toString())); }