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

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

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

WifiManager.updateNetwork介绍

暂无

代码示例

代码示例来源: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 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 updateNetworkTests_permissions() throws Exception {
 int networkId = 1;
 WifiConfiguration wifiConfiguration = new WifiConfiguration();
 wifiConfiguration.networkId = networkId;
 // By default we should have permission to update networks.
 assertThat(wifiManager.updateNetwork(wifiConfiguration)).isEqualTo(networkId);
 // If we don't have permission to update, updateNetwork will return -1.
 shadowOf(wifiManager).setUpdateNetworkPermission(networkId, /* hasPermission = */ false);
 assertThat(wifiManager.updateNetwork(wifiConfiguration)).isEqualTo(-1);
 // Ensure updates can occur if permission is restored.
 shadowOf(wifiManager).setUpdateNetworkPermission(networkId, /* hasPermission = */ true);
 assertThat(wifiManager.updateNetwork(wifiConfiguration)).isEqualTo(networkId);
}

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

network = mWifiManager.updateNetwork(config);

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

boolean result = wm.updateNetwork(wifiConf) != -1; //apply the setting
if(result) result = wm.saveConfiguration(); //Save it
if(result) wm.reassociate(); // reconnect with the new static IP

代码示例来源:origin: TUM-Dev/Campus-Android

int networkId;
if (update) {
  networkId = wifiManager.updateNetwork(conf);
  Utils.log("deleted " + conf.networkId);
} else {

代码示例来源:origin: DeviceConnect/DeviceConnect-Android

if (networkId != -1) {
  mWifiMgr.saveConfiguration();
  mWifiMgr.updateNetwork(wifiConfig);

代码示例来源:origin: steinwurf/adb-join-wifi

networkId = mWifiManager.updateNetwork(wfc);

代码示例来源:origin: GuoZhaoHui628/WifiListConnect

/**
 * 接入某个wifi热点
 */
public static boolean addNetWork(WifiConfiguration config, Context context) {
  WifiManager wifimanager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
  WifiInfo wifiinfo = wifimanager.getConnectionInfo();
  if (null != wifiinfo) {
    wifimanager.disableNetwork(wifiinfo.getNetworkId());
  }
  boolean result = false;
  if (config.networkId > 0) {
    result = wifimanager.enableNetwork(config.networkId, true);
    wifimanager.updateNetwork(config);
  } else {
    int i = wifimanager.addNetwork(config);
    result = false;
    if (i > 0) {
      wifimanager.saveConfiguration();
      return wifimanager.enableNetwork(i, true);
    }
  }
  return result;
}

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

netId = wifiManager.updateNetwork(wifiConfiguration);
if (netId < 0) {
  proxyChangeAsync.onProgressUpdate("Having trouble resetting wifi, hard resetting...");

相关文章