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

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

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

WifiManager.removeNetwork介绍

暂无

代码示例

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

private void restorePreviousConfig() {
  WifiConfiguration config = NetworkManager.getWifiConfiguration(mWifiManager, mPreviousConfig);
  if(config != null) {
    mWifiManager.removeNetwork(config.networkId);
  }
  if(mWifiManager.addNetwork(mPreviousConfig) != -1) {
    mWifiManager.saveConfiguration();
  }
  mPreviousConfig = null;
}

代码示例来源: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
@Config(minSdk = Build.VERSION_CODES.LOLLIPOP)
public void getPrivilegedConfiguredNetworks_shouldReturnConfiguredNetworks() throws Exception {
 WifiConfiguration wifiConfiguration = new WifiConfiguration();
 wifiConfiguration.networkId = 123;
 wifiManager.addNetwork(wifiConfiguration);
 List<WifiConfiguration> list = wifiManager.getPrivilegedConfiguredNetworks();
 assertThat(list.size()).isEqualTo(1);
 wifiManager.removeNetwork(0);
 list = wifiManager.getPrivilegedConfiguredNetworks();
 assertThat(list.size()).isEqualTo(0);
}

代码示例来源: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

mWifiManager.removeNetwork(mPreviousConfig.networkId);

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

/**
 * 移除一个已配置的网络
 */
public void removeWifiConfiguration(WifiConfiguration config) {
  mWifiManager.removeNetwork(config.networkId);
}

代码示例来源:origin: leavesC/WifiFileTransfer

/**
 * 清除指定Wifi的配置信息
 *
 * @param ssid SSID
 */
public static void cleanWifiInfo(Context context, String ssid) {
  WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
  WifiConfiguration wifiConfiguration = isWifiExist(context, ssid);
  if (wifiManager != null && wifiConfiguration != null) {
    wifiManager.removeNetwork(wifiConfiguration.networkId);
  }
}

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

/**
 * 移除所有已配置的网络
 */
public void removeAllWifiConfiguration() {
  List<WifiConfiguration> list = getWifiConfigList();
  if (list == null) {
    return;
  }
  for (WifiConfiguration config : list) {
    mWifiManager.removeNetwork(config.networkId);
  }
}

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

public class KillTimer extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.killtimer);
     WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
     int networkId = wifiManager.getConnectionInfo().getNetworkId();
     wifiManager.removeNetwork(networkId);
     wifiManager.saveConfiguration();
   }}

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

WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
   int networkId = wifiManager.getConnectionInfo().getNetworkId();
   wifiManager.removeNetwork(networkId);
   wifiManager.saveConfiguration();

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

/**
 * 添加热点
 */
public boolean addWifi(WifiConfiguration config) {
  int i = mWifiManager.addNetwork(config);
  if (connectionWifi(i)) {    //连接成功则返回true
    return true;
  }
  mWifiManager.removeNetwork(i);
  return false;
}

代码示例来源:origin: jpkrause/AndroidProxySetter

private void clearWifiConfigs() {
  WifiManager wifiManager = APL.getWifiManager();
  try {
    // remove the existing configurations to ensure that the newly inserted one is the only one
    for (WifiConfiguration wifiConfiguration : wifiManager.getConfiguredNetworks()) {
      wifiManager.removeNetwork(wifiConfiguration.networkId);
    }
  } catch (Exception e) {
    Log.e(TAG, "Error clearing wifi configs", e);
  }
  try {
    APL.enableWifi();
  } catch (Exception e) {
    Log.e(TAG, "Error enabling wifi", e);
  }
  wifiManager.saveConfiguration();
}

代码示例来源:origin: pmbento/karmadetector

private boolean removeDecoyNetworks() {
  //Log.d("WifiScannerService", "Clearing old decoy networks");
  List<WifiConfiguration> l = wifiManager.getConfiguredNetworks();
  if (l != null) {
    for (WifiConfiguration r : l) {
      if (r.SSID.startsWith("\"KD-") && r.SSID.length() == 18) {
        //Log.d("WifiScannerService", "Going to remove network: " + r.SSID);
        boolean ea = wifiManager.removeNetwork(r.networkId);
        //Log.d("WifiPreference", "remove Network returned " + ea);
        if (!ea) {
          addToLog("Error removing decoy network!");
          return false;
        }
      }
    }
    boolean es = wifiManager.saveConfiguration();
    //Log.d("WifiPreference", "saveConfiguration returned " + es);
    if (!es) {
      addToLog("Error saving the network configuration while removing decoy networks!");
      return false;
    }
  }
  return true;
}

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

static public void ConnectToWiFi(String ssid ,String key,Context ctx) {

  WifiConfiguration wifiConfig = new WifiConfiguration();
  wifiConfig.SSID = String.format("\"%s\"", ssid);
  wifiConfig.preSharedKey = String.format("\"%s\"", key);
  WifiManager wifiManager = (WifiManager) ctx.getSystemService(ctx.WIFI_SERVICE);
  int networkId = wifiManager.getConnectionInfo().getNetworkId();
  wifiManager.removeNetwork(networkId);
  wifiManager.saveConfiguration();
  //remember id
  int netId = wifiManager.addNetwork(wifiConfig);
  wifiManager.disconnect();
  wifiManager.enableNetwork(netId, true);
  wifiManager.reconnect();
}

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

public boolean connect(String SSID, WifiCipherType type, String password) {
  while (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
    SystemClock.sleep(100);
  }
  if (TextUtils.isEmpty(SSID) || password == null) {
    return false;
  }
  WifiConfiguration currentConfig = createWifiInfo(SSID, type, password);
  if (currentConfig == null) {
    return false;
  }
  WifiConfiguration tempConfig = exists(SSID);
  if (tempConfig != null) {
    mWifiManager.removeNetwork(tempConfig.networkId);
  }
  int networkId = addNetwork(currentConfig);
  return networkId != -1 && mWifiManager.reconnect();
}

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

WifiConfiguration item = curentList.get(i);
if (ssidName.equals(item.SSID)) {
  wifiManager.removeNetwork(item.networkId);

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

public boolean reconnect(ScanResult result, String password) {
  List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
  boolean enabling = false;
  boolean isOk = false;
  mWifiManager.disconnect();
  for (WifiConfiguration config : configs) {
    if (config.BSSID != null && config.BSSID.equals(result.BSSID)) {
      isOk = mWifiManager.enableNetwork(config.networkId, true);
      enabling = true;
      break;
    }
  }
  if (isOk && !enabling) {
    WifiConfiguration tempConfig = exists(result.BSSID);
    if (tempConfig == null) {
      mWifiManager.removeNetwork(tempConfig.networkId);
    }
    WifiConfiguration config = createWifiInfo(result, password);
    int networkId = addNetwork(config);
    isOk = mWifiManager.enableNetwork(networkId, true);
    if (isOk) {
      mWifiManager.reconnect();
    }
  }
  return isOk;
}

相关文章