public WifiConfiguration getWifiConfiguration(final ScanResult hotsopt, String hotspotSecurity) { final String ssid = convertToQuotedString(hotsopt.SSID); if (ssid.length() == 0) { return null; } final String bssid = hotsopt.BSSID; if (bssid == null) { return null; } if (hotspotSecurity == null) { hotspotSecurity = ConfigSec.getScanResultSecurity(hotsopt); } final List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks(); if (configurations == null) { return null; } for (final WifiConfiguration config : configurations) { if (config.SSID == null || !ssid.equals(config.SSID)) { continue; } if (config.BSSID == null || bssid.equals(config.BSSID)) { final String configSecurity = ConfigSec.getWifiConfigurationSecurity(config); if (hotspotSecurity.equals(configSecurity)) { return config; } } } return null; }
/** Method is beeing called on any click of an preference... */ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (preference.getKey().equals(KEY_WIFI_BASED_SCREEN)) { mWifiList = mWifiManager.getConfiguredNetworks(); if (mWifiList == null) { return false; } for (WifiConfiguration wifi : mWifiList) { // Friendly SSID-Name String ssid = wifi.SSID.replaceAll("\"", ""); // Add PreferenceScreen for each network PreferenceScreen pref = getPreferenceManager().createPreferenceScreen(this); pref.setPersistent(false); pref.setKey("wifiNetwork" + ssid); pref.setTitle(ssid); Intent intent = new Intent(this, ConnectionSettings.class); intent.putExtra("SSID", ssid); pref.setIntent(intent); if (WifiConfiguration.Status.CURRENT == wifi.status) pref.setSummary(R.string.connected); else pref.setSummary(R.string.notInRange); mWifibasedCategory.addPreference(pref); } } return false; }
private void loadNetworkList() { WifiManager wm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> wcs = wm.getConfiguredNetworks(); String[] ssidEntries = null; int n = 3; if (wcs == null) { ssidEntries = new String[n]; ssidEntries[0] = Constraints.WIFI_AND_3G; ssidEntries[1] = Constraints.ONLY_WIFI; ssidEntries[2] = Constraints.ONLY_3G; } else { ssidEntries = new String[wcs.size() + n]; ssidEntries[0] = Constraints.WIFI_AND_3G; ssidEntries[1] = Constraints.ONLY_WIFI; ssidEntries[2] = Constraints.ONLY_3G; for (WifiConfiguration wc : wcs) { if (wc != null && wc.SSID != null) { ssidEntries[n++] = wc.SSID.replace("\"", ""); } else { ssidEntries[n++] = "unknown"; } } } ssidList.setEntries(ssidEntries); ssidList.setEntryValues(ssidEntries); }
public WifiConfiguration getWifiConfiguration(WifiConfiguration configToFind, String security) { final String ssid = configToFind.SSID; if (ssid.length() == 0) { return null; } final String bssid = configToFind.BSSID; if (security == null) { security = ConfigSec.getWifiConfigurationSecurity(configToFind); } final List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks(); for (final WifiConfiguration config : configurations) { if (config.SSID == null || !ssid.equals(config.SSID)) { continue; } if (config.BSSID == null || bssid == null || bssid.equals(config.BSSID)) { final String configSecurity = ConfigSec.getWifiConfigurationSecurity(config); if (security.equals(configSecurity)) { return config; } } } return null; }
public void startScan() { mWifiManager.startScan(); // �õ�ɨ���� mWifiList = mWifiManager.getScanResults(); // �õ����úõ��������� mWifiConfiguration = mWifiManager.getConfiguredNetworks(); }
public void startScan() { mWifiManager.startScan(); // 得到扫描结果 mWifiList = mWifiManager.getScanResults(); // 得到配置好的网络连接 mWifiConfigurations = mWifiManager.getConfiguredNetworks(); }
@Override void initValues() { mContext = Add_DeviceActivity.this; mBackClassName = getBackClassName(); mNowClassName = getNowClassName(); mWifiManger = (WifiManager) getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> listWifiConfiguration = mWifiManger.getConfiguredNetworks(); // Log.e("mWifiManger.isWifiEnabled()", "wifiEnabled:" + mWifiManger.isWifiEnabled()); if (!mWifiManger.isWifiEnabled()) { Toast.makeText(this, getString(R.string.open_wifi), Toast.LENGTH_SHORT).show(); startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)); overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left); } else { for (int i = 0; i < listWifiConfiguration.size(); i++) { if (mWifiManger.getConnectionInfo().getSSID().equals(listWifiConfiguration.get(i).SSID)) { mOriginWifiConfig = listWifiConfiguration.get(i); } } } mWifiScanReceiver = new WifiScanReceiver(); mWifiChangeReceiver = new WifiChangeReceiver(); }
/** * This method initiates the connect process * * @param config an array containing the SSID and the password of the network * @param context android context */ public void connect(String[] config, Context context) { identificationMissing = false; wlanKeyMissing = false; wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); adhoc = new AdhocWifiManager(wifi); ssid = config[0]; identification = preferences.getString("identification", ""); if (identification.equals("")) { identificationMissing = true; } boolean connectedSuccessful = false; // check whether the network is already known, i.e. the password is // already stored in the device for (WifiConfiguration configuredNetwork : wifi.getConfiguredNetworks()) { if (configuredNetwork.SSID.equals("\"".concat(ssid).concat("\""))) { connectedSuccessful = true; networkId = configuredNetwork.networkId; break; } } if (!connectedSuccessful) { for (ScanResult result : wifi.getScanResults()) { if (result.SSID.equals(ssid)) { connectedSuccessful = true; if (result.capabilities.contains("WPA") || result.capabilities.contains("WEP")) { wlanKeyMissing = true; } break; } } } if (connectedSuccessful) { if (identificationMissing || wlanKeyMissing) { identificationWlanKeyDialogFragment = new IdentificationWlanKeyDialogFragment(identificationMissing, wlanKeyMissing); identificationWlanKeyDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog); identificationWlanKeyDialogFragment.show( getFragmentManager(), "identificationWlanKeyDialogFragment"); } else { adhoc.connectToNetwork(networkId, this); } } else { for (int i = 0; i < 2; i++) Toast.makeText( this, getString(R.string.toast_network_not_found_text, ssid), Toast.LENGTH_SHORT) .show(); } }
private void buildAutodownloadSelectedNetworsPreference() { final Activity activity = ui.getActivity(); if (selectedNetworks != null) { clearAutodownloadSelectedNetworsPreference(); } // get configured networks WifiManager wifiservice = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); if (networks != null) { selectedNetworks = new CheckBoxPreference[networks.size()]; List<String> prefValues = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks()); PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); Preference.OnPreferenceClickListener clickListener = preference -> { if (preference instanceof CheckBoxPreference) { String key = preference.getKey(); List<String> prefValuesList = new ArrayList<>(Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks())); boolean newValue = ((CheckBoxPreference) preference).isChecked(); Log.d(TAG, "Selected network " + key + ". New state: " + newValue); int index = prefValuesList.indexOf(key); if (index >= 0 && !newValue) { // remove network prefValuesList.remove(index); } else if (index < 0 && newValue) { prefValuesList.add(key); } UserPreferences.setAutodownloadSelectedNetworks( prefValuesList.toArray(new String[prefValuesList.size()])); return true; } else { return false; } }; // create preference for each known network. attach listener and set // value for (int i = 0; i < networks.size(); i++) { WifiConfiguration config = networks.get(i); CheckBoxPreference pref = new CheckBoxPreference(activity); String key = Integer.toString(config.networkId); pref.setTitle(config.SSID); pref.setKey(key); pref.setOnPreferenceClickListener(clickListener); pref.setPersistent(false); pref.setChecked(prefValues.contains(key)); selectedNetworks[i] = pref; prefScreen.addPreference(pref); } } else { Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); } }
private static void reenableAllAps(final Context ctx) { final WifiManager wifiMgr = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks(); if (configurations != null) { for (final WifiConfiguration config : configurations) { wifiMgr.enableNetwork(config.networkId, false); } } }
// 得到Wifi配置好的信息 public List<WifiConfiguration> getConfiguration() { // 得到配置好的网络信息 wifiConfigList = localWifiManager.getConfiguredNetworks(); for (int i = 0; i < wifiConfigList.size(); i++) { Log.i(TAG, wifiConfigList.get(i).SSID); Log.i(TAG, String.valueOf(wifiConfigList.get(i).networkId)); } return wifiConfigList; }
private WifiConfiguration IsExsits(String SSID) { List<WifiConfiguration> existingConfigs = mWifiManager.getConfiguredNetworks(); for (WifiConfiguration existingConfig : existingConfigs) { if (existingConfig.SSID.equals("\"" + SSID + "\"")) { return existingConfig; } } return null; }
/** * Wifi接続設定情報を取得する * * @return WifiConfiguration wifi接続情報 */ public WifiConfiguration getWifiConfig(String ssid) { List<WifiConfiguration> configuredNetworks = mWifiManager.getConfiguredNetworks(); for (WifiConfiguration wifiConfiguration : configuredNetworks) { if (wifiConfiguration.SSID.equals(ssid)) { return wifiConfiguration; } } return null; }
private static Integer findNetworkInExistingConfig(WifiManager wifiManager, String ssid) { List<WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks(); for (WifiConfiguration existingConfig : existingConfigs) { if (existingConfig.SSID.equals(ssid)) { return existingConfig.networkId; } } return null; }
/** * 判断wifi是否存在 * * @param SSID * @param wifiManager * @return */ public static WifiConfiguration isExsits(String SSID, WifiManager wifiManager) { List<WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks(); for (WifiConfiguration existingConfig : existingConfigs) { if (existingConfig.SSID.equals("\"" + SSID + "\"")) { return existingConfig; } } return null; }
private int getMaxPriority() { final List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks(); int pri = 0; for (final WifiConfiguration config : configurations) { if (config.priority > pri) { pri = config.priority; } } return pri; }
String[] getWifiNetworks() { List<WifiConfiguration> networks = mWifimanager.getConfiguredNetworks(); if (networks == null) { return new String[0]; } String[] ssids = new String[networks.size()]; for (int ii = 0; ii < networks.size(); ii++) { ssids[ii] = networks.get(ii).SSID; } return ssids; }
private int getNetworkId(ScanResult result) { mWifiConfigList = mWifiManager.getConfiguredNetworks(); int total = mWifiConfigList.size(); for (int i = 0; i < total; i++) { if (mWifiConfigList.get(i).SSID.equals(WifiUtil.convertToQuotedString(result.SSID))) { return mWifiConfigList.get(i).networkId; } } return -1; }
// 获取一个已经保存的wifi信息 public int IsConfiguration(String SSID) { mWifiConfiguration = mWifiManager.getConfiguredNetworks(); // ??????ú????????? Log.i("IsConfiguration", String.valueOf(mWifiConfiguration.size())); for (int i = 0; i < mWifiConfiguration.size(); i++) { Log.i(mWifiConfiguration.get(i).SSID, String.valueOf(mWifiConfiguration.get(i).networkId)); if (mWifiConfiguration.get(i).SSID.equals("\"" + SSID + "\"")) { // ?????? return mWifiConfiguration.get(i).networkId; } } return -1; }
public static void disconnect() { List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for (WifiConfiguration i : list) { if (i.SSID.equals(FirstSettings_two.first_ssid)) { WifiConfiguration conf = new WifiConfiguration(); conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK); conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); wifiManager.disconnect(); break; } } }
private int shiftPriorityAndSave() { final List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks(); sortByPriority(configurations); final int size = configurations.size(); for (int i = 0; i < size; i++) { final WifiConfiguration config = configurations.get(i); config.priority = i; mWifiManager.updateNetwork(config); } mWifiManager.saveConfiguration(); return size; }
public static boolean isWiFiApConfigured(final Context context) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); if (configs == null) return false; // Check for existing APs. final String conferenceSSID = String.format("\"%s\"", Config.WIFI_SSID); for (WifiConfiguration config : configs) { if (conferenceSSID.equalsIgnoreCase(config.SSID)) return true; } return false; }
public void getWifiList() { if (mWifiManager.startScan() == true) System.out.println("扫描成功"); // 得到扫描结果 mWifiList = mWifiManager.getScanResults(); System.out.println("mWifiList.size()=" + mWifiList.size()); if (mWifiList == null) { System.out.println("mWifiList is null"); } else { System.out.println("mWifiList=" + mWifiList); } // 得到配置好的网络连接 mWifiConfiguration = mWifiManager.getConfiguredNetworks(); }
public void connect(final Host host) { Log.d(TAG, "trying to connect to AP:" + host.access_point); final List<WifiConfiguration> hosts = mManager.getConfiguredNetworks(); int networkId = -1; for (WifiConfiguration conf : hosts) { Log.d(TAG, "trying host:" + conf.SSID); if (conf.SSID.equalsIgnoreCase("\"" + host.access_point + "\"")) { networkId = conf.networkId; Log.d(TAG, "found hosts AP in Android with ID:" + networkId); break; } } mManager.enableNetwork(networkId, true); }
public List<WifiConfiguration> getConfiguredNetworks() { List<WifiConfiguration> configs = new ArrayList<WifiConfiguration>(); List<WifiConfiguration> configuredNetworks = mWifiManager.getConfiguredNetworks(); if (configuredNetworks == null) { configuredNetworks = new ArrayList<WifiConfiguration>(); } for (WifiConfiguration config : configuredNetworks) { String ssid = getSsidName(config.SSID); if (!TextUtils.isEmpty(ssid)) { configs.add(config); } } return configs; }
public String getIpAssignment() { Log.d(TAG, "<<<<<<<<<<<getNetworkTypeName() <<<<<<<<<" + getNetworkTypeName()); if (getNetworkTypeName().equals("WIFI")) { Log.d(TAG, "<<<<<<<<<<<当前网络为wifi<<<<<<<<<"); WifiManager wm = (WifiManager) mContext.getSystemService(mContext.WIFI_SERVICE); if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { WifiInfo wifiInfo = wm.getConnectionInfo(); String ssid = wifiInfo.getSSID(); List<WifiConfiguration> wifiConfigurations = wm.getConfiguredNetworks(); for (WifiConfiguration config : wifiConfigurations) { if (config.SSID.equals(ssid)) { String IP_Assignment = config.toString(); Log.i(TAG, "WIFI_IP_Assignment: " + IP_Assignment); String[] sss = IP_Assignment.split("\n"); Log.i(TAG, "<<<<<<String[] sss<<<<<<< " + sss.length + "<<<<<<"); IP_Assignment = sss[20]; IP_Assignment = IP_Assignment.substring(IP_Assignment.lastIndexOf(":") + 1).toString(); return IP_Assignment; } } } return "UNASSIGNED"; } else { String Ip_Assignment = null; // ContentResolver cr = mContext.getContentResolver(); // try { // if (Settings.System.getInt(cr, ETHERNET_USE_STATIC_IP) == 0) { // Log.d(TAG, // "checkUseStaticIp() : user set to use DHCP, about to Return."); // // Ip_Assignment = "DHCP"; // } // Ip_Assignment = "STATIC"; // } catch (Settings.SettingNotFoundException e) { // Ip_Assignment = "DHCP"; // } // Log.i(TAG, "ETHERNET_IP_Assignment: " + Ip_Assignment); IpConfiguration mIpConfiguration = new IpConfiguration(); mIpConfiguration.getIpAssignment(); Log.d(TAG, "ipassignment" + mIpConfiguration.getIpAssignment()); // return Ip_Assignment; if (mIpConfiguration.getIpAssignment().equals(IpAssignment.DHCP)) { return "DHCP"; } else { return "STATIC"; } // return mIpConfiguration.getIpAssignment(); } }
/** * Helper method to decide whether to bypass conference WiFi setup. Return true if WiFi AP is * already configured (WiFi adapter enabled) or WiFi configuration is complete as per shared * preference. */ public static boolean shouldBypassWiFiSetup(final Context context) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // Is WiFi on? if (wifiManager.isWifiEnabled()) { // Check for existing APs. final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks(); final String conferenceSSID = String.format("\"%s\"", Config.WIFI_SSID); for (WifiConfiguration config : configs) { if (conferenceSSID.equalsIgnoreCase(config.SSID)) return true; } } return WIFI_CONFIG_DONE.equals(getWiFiConfigStatus(context)); }
public static void reconnect1() { try { List<WifiConfiguration> list = wifiManager.getConfiguredNetworks(); for (WifiConfiguration i : list) { if (i.SSID.equals(FirstSettings_two.first_ssid)) { wifiManager.enableNetwork(i.networkId, true); wifiManager.reconnect(); break; } } } catch (Exception e) { e.printStackTrace(); } ; }
private boolean isConfigured(ScanResult result) { if (WifiConst.DummyMode) { return false; } mWifiConfigList = mWifiManager.getConfiguredNetworks(); int total = mWifiConfigList.size(); for (int i = 0; i < total; i++) { if (mWifiConfigList.get(i).SSID.equals(WifiUtil.convertToQuotedString(result.SSID))) { return true; } } return false; }
// 链接并且保持wifi public boolean ConnectASaveWifi(int wifiId) { mWifiConfiguration = mWifiManager.getConfiguredNetworks(); // ??????ú????????? for (int i = 0; i < mWifiConfiguration.size(); i++) { WifiConfiguration wifi = mWifiConfiguration.get(i); if (wifi.networkId == wifiId) { while (!(mWifiManager.enableNetwork(wifiId, true))) { mWifiManager.updateNetwork(wifi); Log.i("ConnectWifi", String.valueOf(mWifiConfiguration.get(wifiId).status)); } return true; } } return false; }