List of usage examples for android.net.wifi WifiManager setWifiEnabled
public boolean setWifiEnabled(boolean enabled)
From source file:com.example.android.listentgt.MainActivity.java
public boolean turnOnWifi(View view) { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(!isWifiP2pEnabled); // true or false to activate/deactivate wifi isWifiP2pEnabled = !isWifiP2pEnabled; //update the device info ((DeviceListFragment) getFragment2()).updateThisDevice(((DeviceListFragment) getFragment2()).getDevice()); return true;//from w ww . j a v a2 s .c o m }
From source file:fm.feed.android.SampleApp.fragment.TestFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mBtnTune.setOnClickListener(tune);/*ww w .j a va 2 s . c o m*/ mBtnPlay.setOnClickListener(play); mBtnPause.setOnClickListener(pause); mBtnSkip.setOnClickListener(skip); mBtnLike.setOnClickListener(like); mBtnUnlike.setOnClickListener(unlike); mBtnDislike.setOnClickListener(dislike); mBtnHistory.setOnClickListener(history); mStationsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mBtnToggleWifi.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ConnectivityManager cm = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(!isConnected); // true or false to activate/deactivate wifi mBtnToggleWifi.setText(!isConnected ? "Wifi ON" : "Wifi OFF"); } }); resetTrackInfo(); if (mPlayer.hasPlay()) { updateTrackInfo(mPlayer.getPlay()); } if (mPlayer.hasStationList()) { updateStations(mPlayer.getStationList()); } }
From source file:org.openremote.android.test.console.net.ORNetworkCheckTest.java
private void enableWifi(boolean enable) { WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); if (enable && wifi.isWifiEnabled()) return;//from w w w .j a va 2 s. co m if (!enable && !wifi.isWifiEnabled()) return; if (enable && !wifi.isWifiEnabled()) { if (!wifi.setWifiEnabled(true)) fail("Cannot enable WiFi"); } else { wifi.disconnect(); wifi.setWifiEnabled(false); } // wait for it... for (int iterations = 0; iterations < 10; iterations++) { SystemClock.sleep(500); if (enable && wifi.isWifiEnabled()) break; if (!enable && !wifi.isWifiEnabled()) break; } }
From source file:tf.nox.wifisetup.WifiSetup.java
private void saveWifiConfig() { WifiManager wifiManager = (WifiManager) this.getApplicationContext().getSystemService(WIFI_SERVICE); wifiManager.setWifiEnabled(true); WifiConfiguration currentConfig = new WifiConfiguration(); List<WifiConfiguration> configs = null; for (int i = 0; i < 10 && configs == null; i++) { configs = wifiManager.getConfiguredNetworks(); try {//from ww w.jav a 2 s . co m Thread.sleep(1); } catch (InterruptedException e) { continue; } } if (check5g.isChecked()) { ssid = "34C3"; } else { ssid = "34C3-legacy"; } subject_match = "/CN=radius.c3noc.net"; altsubject_match = "DNS:radius.c3noc.net"; s_username = username.getText().toString(); s_password = password.getText().toString(); realm = ""; if (s_username.equals("") && s_password.equals("")) { s_username = "34c3"; s_password = "34c3"; } else { if (s_username.indexOf("@") >= 0) { int idx = s_username.indexOf("@"); realm = s_username.substring(idx); } } // Use the existing eduroam profile if it exists. boolean ssidExists = false; if (configs != null) { for (WifiConfiguration config : configs) { if (config.SSID.equals(surroundWithQuotes(ssid))) { currentConfig = config; ssidExists = true; break; } } } currentConfig.SSID = surroundWithQuotes(ssid); currentConfig.hiddenSSID = false; currentConfig.priority = 40; currentConfig.status = WifiConfiguration.Status.DISABLED; currentConfig.allowedKeyManagement.clear(); currentConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP); // GroupCiphers (Allow most ciphers) currentConfig.allowedGroupCiphers.clear(); currentConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); currentConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); currentConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); // PairwiseCiphers (CCMP = WPA2 only) currentConfig.allowedPairwiseCiphers.clear(); currentConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); // Authentication Algorithms (OPEN) currentConfig.allowedAuthAlgorithms.clear(); currentConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); // Protocols (RSN/WPA2 only) currentConfig.allowedProtocols.clear(); currentConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN); // Enterprise Settings HashMap<String, String> configMap = new HashMap<String, String>(); configMap.put(INT_SUBJECT_MATCH, subject_match); configMap.put(INT_ALTSUBJECT_MATCH, altsubject_match); configMap.put(INT_ANONYMOUS_IDENTITY, "anonymous" + realm); configMap.put(INT_IDENTITY, s_username); configMap.put(INT_PASSWORD, s_password); configMap.put(INT_EAP, "TTLS"); configMap.put(INT_PHASE2, "auth=PAP"); configMap.put(INT_ENGINE, "0"); // configMap.put(INT_CA_CERT, INT_CA_PREFIX + ca_name); applyAndroid43EnterpriseSettings(currentConfig, configMap); if (!ssidExists) { int networkId = wifiManager.addNetwork(currentConfig); wifiManager.enableNetwork(networkId, false); } else { wifiManager.updateNetwork(currentConfig); wifiManager.enableNetwork(currentConfig.networkId, false); } wifiManager.saveConfiguration(); }
From source file:com.laer.easycast.ImagePane.java
public void WiFiOptions() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override//from w w w. jav a 2s .c om public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: // Yes button clicked WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); break; case DialogInterface.BUTTON_NEGATIVE: // No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage( "WiFi needs to be on for com.laer.easycast.streaming to a device. Would you like to turn it on?") .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show(); }
From source file:org.sipdroid.sipua.ui.Receiver.java
static void enable_wifi(boolean enable) { if (!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_OWNWIFI, org.sipdroid.sipua.ui.Settings.DEFAULT_OWNWIFI)) return;//from w ww . j a va 2s . c o m if (enable && !PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean( org.sipdroid.sipua.ui.Settings.PREF_WIFI_DISABLED, org.sipdroid.sipua.ui.Settings.DEFAULT_WIFI_DISABLED)) return; WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); ContentResolver cr = Receiver.mContext.getContentResolver(); if (!enable && Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON, 0) == 0) return; Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit(); edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_WIFI_DISABLED, !enable); edit.commit(); /* if (enable) { Intent intent = new Intent(WifiManager.WIFI_STATE_CHANGED_ACTION); intent.putExtra(WifiManager.EXTRA_NEW_STATE, wm.getWifiState()); mContext.sendBroadcast(intent); } */ wm.setWifiEnabled(enable); }
From source file:fm.feed.android.testapp.fragment.TestFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mBtnTune.setOnClickListener(tune);//from w w w . ja v a 2s . c o m mBtnPlay.setOnClickListener(play); mBtnPause.setOnClickListener(pause); mBtnSkip.setOnClickListener(skip); mBtnLike.setOnClickListener(like); mBtnUnlike.setOnClickListener(unlike); mBtnDislike.setOnClickListener(dislike); mBtnHistory.setOnClickListener(history); mPlacementsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mStationsView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mBtnToggleWifi.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ConnectivityManager cm = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(!isConnected); // true or false to activate/deactivate wifi mBtnToggleWifi.setText(!isConnected ? "Wifi ON" : "Wifi OFF"); } }); List<HashMap<String, Integer>> fillMaps = new ArrayList<HashMap<String, Integer>>(); for (Integer p : mPlacements) { HashMap<String, Integer> map = new HashMap<String, Integer>(); map.put("Placement", p); fillMaps.add(map); } final SimpleAdapter adapter = new SimpleAdapter(getActivity(), fillMaps, android.R.layout.simple_list_item_1, new String[] { "Placement" }, new int[] { android.R.id.text1 }); mPlacementsView.setAdapter(adapter); mPlacementsView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mSelectedPlacementsIndex = position; HashMap<String, Integer> item = (HashMap<String, Integer>) adapter.getItem(position); Integer placementId = item.get("Placement"); Toast.makeText(getActivity(), placementId.toString(), Toast.LENGTH_LONG).show(); mPlayer.setPlacementId(placementId); } }); resetTrackInfo(); if (mPlayer.hasPlay()) { updateTrackInfo(mPlayer.getPlay()); } if (mPlayer.hasStationList()) { updateStations(mPlayer.getStationList()); } }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
@Override public void onPause() { if (locationManager != null) locationManager.removeUpdates(this); // Si habia descargas en curso, pararlas if (descargaEstaciones != null) { descargaEstaciones.cancel(true); descargaEstaciones = null;//from w w w . jav a2s . co m } WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(this.estatWifi); super.onPause(); }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
public void onResume() { // Reactivar suscripcin a ubicaciones activarUbicacion();/*from w w w . j av a 2 s.c o m*/ // Reactivar wifi si es necesario if (prefs.getBoolean("activarWifiPref", false)) { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(true); } super.onResume(); }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals("ocultarVaciosPref")) actualizarListado();//from w ww .j a v a2s .com if (key.equals("activarWifiPref")) { if (sharedPreferences.getBoolean("activarWifiPref", false)) { WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(true); } } }