android.net.wifi.WifiManager.getConfiguredNetworks()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(423)

本文整理了Java中android.net.wifi.WifiManager.getConfiguredNetworks()方法的一些代码示例,展示了WifiManager.getConfiguredNetworks()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.getConfiguredNetworks()方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:getConfiguredNetworks

WifiManager.getConfiguredNetworks介绍

暂无

代码示例

代码示例来源:origin: cSploit/android

public static int getMaxPriority(WifiManager wifiManager){
 List<WifiConfiguration> configurations = wifiManager.getConfiguredNetworks();
 int pri = 0;
 for(WifiConfiguration config : configurations){
  if(config.priority > pri){
   pri = config.priority;
  }
 }
 return pri;
}

代码示例来源:origin: stackoverflow.com

WifiConfiguration wifiConf = null;
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
    List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();        
    for (WifiConfiguration conf : configuredNetworks){
      if (conf.networkId == connectionInfo.getNetworkId()){
        wifiConf = conf;
        break;              
      }
    }

代码示例来源:origin: cSploit/android

/**
  * retrieve a stored wifi configuration that matches arguments
  * @param wifiMgr a WiFiManager instance
  * @param ssid the network SSID to search
  * @param bssid an optional BSSID, it can be null
  * @return the found WifiConfiguration on success, null otherwise
  */
 public static WifiConfiguration getWifiConfiguration(WifiManager wifiMgr, String ssid, String bssid) {
  if(wifiMgr == null || ssid == null || ssid.isEmpty()) {
   return null;
  }

  List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();

  for(WifiConfiguration config : configurations) {
   if(ssid.equals(config.SSID) && ( bssid == null || config.BSSID == null || bssid.equals(config.BSSID))) {
    return config;
   }
  }
  return null;
 }
}

代码示例来源:origin: cSploit/android

private void onEnd() {
  List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks();
  boolean restore = false;
  if(configurations != null) {
    for(WifiConfiguration config : configurations){
      mWifiManager.enableNetwork(config.networkId, false);
      restore = restore || (mPreviousConfig != null && mPreviousConfig.SSID.equals(config.SSID) &&
          ( mCurrentKey == null || !mCurrentKey.equals(mPreviousConfig.preSharedKey) ) );
    }
  }
  if(restore && !mConnected) {
    restorePreviousConfig();
  }
}

代码示例来源:origin: cSploit/android

public static int shiftPriorityAndSave(final WifiManager wifiMgr){
 final List<WifiConfiguration> configurations = wifiMgr
  .getConfiguredNetworks();
 sortByPriority(configurations);
 final int size = configurations.size();
 for(int i = 0; i < size; i++){
  final WifiConfiguration config = configurations.get(i);
  config.priority = i;
  wifiMgr.updateNetwork(config);
 }
 wifiMgr.saveConfiguration();
 return size;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void removeNetwork() throws Exception {
 WifiConfiguration wifiConfiguration = new WifiConfiguration();
 wifiConfiguration.networkId = 123;
 wifiManager.addNetwork(wifiConfiguration);
 List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
 assertThat(list.size()).isEqualTo(1);
 wifiManager.removeNetwork(0);
 list = wifiManager.getConfiguredNetworks();
 assertThat(list.size()).isEqualTo(0);
}

代码示例来源:origin: cSploit/android

public void onFailedConnection(){
  mWifiManager.removeNetwork(mCurrentNetworkId);
  if(!mKeyList.isEmpty()) {
    nextConnectionAttempt();
    return;
  }
  mStatusText.setText(Html.fromHtml(getString(R.string.connection_to) + mCurrentAp.SSID + getString(R.string.connection_to2)));
  List<WifiConfiguration> configurations = mWifiManager.getConfiguredNetworks();
  if(configurations != null){
    for(WifiConfiguration config : configurations){
      mWifiManager.enableNetwork(config.networkId, false);
    }
  }
  mConnectionReceiver.unregister();
  onEnd();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldRecordTheLastAddedNetwork() throws Exception {
 WifiConfiguration wifiConfiguration = new WifiConfiguration();
 wifiConfiguration.networkId = -1;
 int networkId = wifiManager.addNetwork(wifiConfiguration);
 assertThat(networkId).isEqualTo(0);
 assertThat(wifiManager.getConfiguredNetworks().get(0)).isNotSameAs(wifiConfiguration);
 assertThat(wifiConfiguration.networkId).isEqualTo(-1);
 assertThat(wifiManager.getConfiguredNetworks().get(0).networkId).isEqualTo(0);
 WifiConfiguration anotherConfig = new WifiConfiguration();
 assertThat(wifiManager.addNetwork(anotherConfig)).isEqualTo(1);
 assertThat(anotherConfig.networkId).isEqualTo(-1);
 assertThat(wifiManager.getConfiguredNetworks().get(1).networkId).isEqualTo(1);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void updateNetwork_shouldRejectNullandNewConfigs() throws Exception {
 WifiConfiguration config = new WifiConfiguration();
 config.networkId = -1;
 assertThat(wifiManager.updateNetwork(config)).isEqualTo(-1);
 assertThat(wifiManager.updateNetwork(null)).isEqualTo(-1);
 assertThat(wifiManager.getConfiguredNetworks()).isEmpty();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void updateNetwork_shouldReplaceNetworks() throws Exception {
 WifiConfiguration wifiConfiguration = new WifiConfiguration();
 wifiConfiguration.networkId = -1;
 wifiManager.addNetwork(wifiConfiguration);
 WifiConfiguration anotherConfig = new WifiConfiguration();
 int networkId = wifiManager.addNetwork(anotherConfig);
 assertThat(networkId).isEqualTo(1);
 WifiConfiguration configuration = new WifiConfiguration();
 configuration.networkId = networkId;
 configuration.priority = 44;
 assertThat(wifiManager.updateNetwork(configuration)).isEqualTo(networkId);
 List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
 assertThat(configuredNetworks.size()).isEqualTo(2);
 assertThat(configuration.priority).isEqualTo(44);
 assertThat(configuredNetworks.get(1).priority).isEqualTo(44);
}

代码示例来源:origin: syncthing/syncthing-android

/**
 * Load the configured WiFi networks, sort them by SSID.
 *
 * @return a sorted array of WifiConfiguration, or null, if data cannot be retrieved
 */
private WifiConfiguration[] loadConfiguredNetworksSorted() {
  WifiManager wifiManager = (WifiManager)
      getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
  if (wifiManager != null) {
    List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
    // if WiFi is turned off, getConfiguredNetworks returns null on many devices
    if (configuredNetworks != null) {
      WifiConfiguration[] result = configuredNetworks.toArray(new WifiConfiguration[configuredNetworks.size()]);
      Arrays.sort(result, (lhs, rhs) -> {
        // See #620: There may be null-SSIDs
        String l = lhs.SSID != null ? lhs.SSID : "";
        String r = rhs.SSID != null ? rhs.SSID : "";
        return l.compareToIgnoreCase(r);
      });
      return result;
    }
  }
  // WiFi is turned off or device doesn't have WiFi
  return null;
}

代码示例来源:origin: mayubao/KuaiChuan

/**
 * wifi扫描
 */
public void startScan(){
  mWifiManager.startScan();
  mScanResultList = mWifiManager.getScanResults();
  mWifiConfigurations = mWifiManager.getConfiguredNetworks();
}

代码示例来源:origin: stackoverflow.com

List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
for (WifiConfiguration config : configs) {
  textStatus+= "\n\n" + config.toString();

代码示例来源:origin: luhaoaimama1/zone-sdk

/**
 * 得到配置好的网络
 * 
 * @return
 */
public List<WifiConfiguration> getConfiguration() {
  return mWifiManager.getConfiguredNetworks();
}
/**

代码示例来源:origin: TeamFatCat/Easy_Transfer

/**
 * 返回已配置的wifi
 */
public List<WifiConfiguration> getWifiConfigList() {
  return mWifiManager.getConfiguredNetworks();
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private List<WifiConfiguration> wifiConfiguration() {
  try {
    return wifiManager.getConfiguredNetworks();
  } catch (Exception e) {
    // critical error: do not die
    return new ArrayList<>();
  }
}

代码示例来源:origin: gizwits/GOpenSource_AppKit_Android_AS

private WifiConfiguration isExsits(String SSID) {
  List<WifiConfiguration> existingConfigs = wifiManager
      .getConfiguredNetworks();
  for (WifiConfiguration existingConfig : existingConfigs) {
    if (existingConfig.SSID.equals("\"" + SSID + "\"")) {
      return existingConfig;
    }
  }
  return null;
}

代码示例来源:origin: JackWHLiu/jackknife

public void startScan() {
  mWifiManager.startScan();
  mScanResults = mWifiManager.getScanResults();
  mWifiConfigurations = mWifiManager.getConfiguredNetworks();
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private void withWiFiManager() {
  when(wifiManager.isWifiEnabled()).thenReturn(false);
  when(wifiManager.startScan()).thenReturn(true);
  when(wifiManager.getScanResults()).thenReturn(scanResults);
  when(wifiManager.getConnectionInfo()).thenReturn(wifiInfo);
  when(wifiManager.getConfiguredNetworks()).thenReturn(configuredNetworks);
}

代码示例来源:origin: VREMSoftwareDevelopment/WiFiAnalyzer

private void verifyWiFiManager() {
  verify(wifiManager).isWifiEnabled();
  verify(wifiManager).setWifiEnabled(true);
  verify(wifiManager).startScan();
  verify(wifiManager).getScanResults();
  verify(wifiManager).getConnectionInfo();
  verify(wifiManager).getConfiguredNetworks();
}

相关文章