本文整理了Java中android.net.wifi.WifiManager.addNetwork()
方法的一些代码示例,展示了WifiManager.addNetwork()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.addNetwork()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:addNetwork
暂无
代码示例来源: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
int res = wifiManag.addNetwork(selectedConfig);
Log.d("WifiPreference", "add Network returned " + res );
boolean b = wifiManag.enableNetwork(selectedConfig.networkId, false);
代码示例来源:origin: stackoverflow.com
int res = wifi.addNetwork(wc);
Log.d("WifiPreference", "add Network returned " + res );
boolean es = wifi.saveConfiguration();
代码示例来源: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 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 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: 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: robolectric/robolectric
@Test
public void reconnect_updatesConnectivityManager() {
// GIVEN
WifiConfiguration config = new WifiConfiguration();
config.SSID = "SSID";
int netId = wifiManager.addNetwork(config);
wifiManager.enableNetwork(netId, false);
// WHEN
wifiManager.reconnect();
// THEN
NetworkInfo networkInfo =
((ConnectivityManager)
ApplicationProvider.getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE))
.getActiveNetworkInfo();
assertThat(networkInfo.getType()).isEqualTo(ConnectivityManager.TYPE_WIFI);
assertThat(networkInfo.isConnected()).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reconnect_shouldEnableDhcp() {
// GIVEN
WifiConfiguration config = new WifiConfiguration();
config.SSID = "SSID";
int netId = wifiManager.addNetwork(config);
wifiManager.enableNetwork(netId, false);
// WHEN
wifiManager.reconnect();
// THEN
assertThat(wifiManager.getDhcpInfo()).isNotNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reconnect_setsConnectionInfo() {
// GIVEN
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "SSID";
int netId = wifiManager.addNetwork(wifiConfiguration);
wifiManager.enableNetwork(netId, false);
// WHEN
wifiManager.reconnect();
// THEN
assertThat(wifiManager.getConnectionInfo().getSSID()).contains("SSID");
}
代码示例来源:origin: cSploit/android
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
network = mWifiManager.addNetwork(config);
if(network != -1){
if(mWifiManager.saveConfiguration()){
代码示例来源:origin: mayubao/KuaiChuan
/**
* 添加到指定Wifi网络 /切换到指定Wifi网络
* @param wf
* @return
*/
public boolean addNetwork(WifiConfiguration wf){
//断开当前的连接
disconnectCurrentNetwork();
//连接新的连接
int netId = mWifiManager.addNetwork(wf);
boolean enable = mWifiManager.enableNetwork(netId, true);
return enable;
}
代码示例来源:origin: stackoverflow.com
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
// setup a wifi configuration
WifiConfiguration wc = new WifiConfiguration();
wc.SSID = "\"YOUR_SSID\"";
wc.preSharedKey = "\"YOUR_PASSWORD\"";
wc.status = WifiConfiguration.Status.ENABLED;
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
// connect to and enable the connection
int netId = wifiManager.addNetwork(wc);
wifiManager.enableNetwork(netId, true);
wifiManager.setWifiEnabled(true);
代码示例来源:origin: LiqiNew/MyUtils
/**
* 添加一个网络并连接.
*/
public void addNetWork(WifiConfiguration configuration) {
int wcgId = mWifiManager.addNetwork(configuration);
mWifiManager.enableNetwork(wcgId, true);
}
代码示例来源:origin: 18Gray/CommonUtils
/**
* 添加一个网络并连接
* @param wcg
* @param context
*/
public boolean addNetwork(WifiConfiguration wcg, Context context)
{
int wcgID = wifiManager.addNetwork(wcg);
boolean b = wifiManager.enableNetwork(wcgID, true);
return b;
}
代码示例来源:origin: stackoverflow.com
WifiManager wifiManager = (WifiManager)
MonitorActivity.this.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
int numberOfLevels = 5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
Log.e("level", "" + level);
// you will get the levels. Using these levels you can calculate strenghts.
代码示例来源: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: 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: bparmentier/WiFiKeyShare
private void doConnect(WifiManager wifiManager) {
int networkId = wifiManager.addNetwork(wifiConfiguration);
if (networkId < 0) {
showFailToast();
} else {
boolean connected = wifiManager.enableNetwork(networkId, true);
if (connected) {
Toast.makeText(ConfirmConnectToWifiNetworkActivity.this,
R.string.confirm_connection_status_wifi_connected, Toast.LENGTH_SHORT).show();
} else {
showFailToast();
}
}
}
代码示例来源:origin: stackoverflow.com
WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
int netid = wm.addNetwork(wc);
wm.enableNetwork(netid , true);
if (wm.isWifiEnabled()) {
wm.reconnect();
} else {
wm.setWifiEnabled(true);
}
// ...
// now wait for broadcast that connection was made
内容来源于网络,如有侵权,请联系作者删除!