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

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

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

WifiManager.saveConfiguration介绍

暂无

代码示例

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

boolean b = wifiManag.enableNetwork(selectedConfig.networkId, false);
Log.d("WifiPreference", "enableNetwork returned " + b );
boolean c = wifiManag.saveConfiguration();
Log.d("WifiPreference", "Save configuration returned " + c );
boolean d = wifiManag.enableNetwork(res, true);

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

int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean es = wifi.saveConfiguration();
Log.d("WifiPreference", "saveConfiguration returned " + es );
boolean b = wifi.enableNetwork(res, true);

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

@Test
public void shouldSaveConfigurations() throws Exception {
 assertThat(wifiManager.saveConfiguration()).isTrue();
 assertThat(shadowOf(wifiManager).wasConfigurationSaved()).isTrue();
}

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

if(mWifiManager.saveConfiguration()){
  config = NetworkManager.getWifiConfiguration(mWifiManager, config);
      if(mWifiManager.saveConfiguration()){

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

public int addNetwork(WifiConfiguration config) {
  if (config == null) {
    return -1;
  }
  int networkId = mWifiManager.addNetwork(config);
  if (mWifiManager.enableNetwork(networkId, true)) {
    boolean isOk = mWifiManager.saveConfiguration();
    if (isOk) {
      return networkId;
    }
  }
  return -1;
}

代码示例来源:origin: qyxxjd/BaseProject

/**
 * 连接wifi
 */
@RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE) public boolean connection(
    @NonNull WifiConfiguration wifiConfiguration) {
  int networkId = mWifiManager.addNetwork(wifiConfiguration);
  if (networkId != -1) {
    boolean result = mWifiManager.enableNetwork(networkId, true);
    if (result) {
      mWifiManager.saveConfiguration();
    }
    return result;
  }
  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: qyxxjd/AndroidBasicProject

/**
 * 连接wifi
 * @param wifiConfiguration
 * @return
 */
@RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE)
public boolean connection(WifiConfiguration wifiConfiguration) {
  int networkId = mWifiManager.addNetwork(wifiConfiguration);
  if (networkId != -1) {
    boolean result = mWifiManager.enableNetwork(networkId, true);
    if(result){
      mWifiManager.saveConfiguration();
    }
    return result;
  }
  return false;
}

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

boolean es = wifiManager.saveConfiguration();

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

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

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

int res = wifi.addNetwork(checkPreviousConfiguration(wc)); 
Log.d("WifiPreference", "add Network returned " + res ); 
boolean es = wifi.saveConfiguration(); 
Log.d("WifiPreference", "saveConfiguration returned " + es ); 
boolean b = wifi.enableNetwork(res, true);

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

public void onClick(View v) {
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + your_net_name + "\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if(!wifiManager.isWifiEnabled()){
  wifiManager.setWifiEnabled(true);
}
List<WifiConfiguration> configuredNetworks = wifiManager.getConfiguredNetworks();
for (WifiConfiguration configuredNetwork : configuredNetworks) {
   if (currSSID().equals(configuredNetwork.SSID)) { // I took care of the removel of the "" in configuredNetwork.SSID in my code  
    //configuredNetwork .allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); // you don't need it here
    wifiManager.disconnect();
    wifiManager.enableNetwork(configuredNetwork.networkId, true);
    wifiManager.reconnect();
    wifiManager.saveConfiguration(); // to save your new changes to the network
    break;
  }
}

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

wifiManager.saveConfiguration();
wifiManager.disconnect();
wifiManager.enableNetwork(netId, true);

相关文章