本文整理了Java中android.net.wifi.WifiManager.enableNetwork()
方法的一些代码示例,展示了WifiManager.enableNetwork()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.enableNetwork()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:enableNetwork
暂无
代码示例来源: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: stackoverflow.com
int res = wifiManag.addNetwork(selectedConfig);
Log.d("WifiPreference", "add Network returned " + res );
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);
Log.d("WifiPreference", "enableNetwork returned " + d );
代码示例来源: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 shouldEnableNetworks() throws Exception {
wifiManager.enableNetwork(666, true);
Pair<Integer, Boolean> lastEnabled = shadowOf(wifiManager).getLastEnabledNetwork();
assertThat(lastEnabled).isEqualTo(new Pair<>(666, true));
wifiManager.enableNetwork(777, false);
lastEnabled = shadowOf(wifiManager).getLastEnabledNetwork();
assertThat(lastEnabled).isEqualTo(new Pair<>(777, false));
}
代码示例来源:origin: stackoverflow.com
boolean es = wifi.saveConfiguration();
Log.d("WifiPreference", "saveConfiguration returned " + es );
boolean b = wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b );
代码示例来源: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: cSploit/android
if(mWifiManager.enableNetwork(network, false)){
if(mWifiManager.saveConfiguration()){
if(mWifiManager.enableNetwork(config.networkId, true)){
return mWifiManager.reassociate() ? config.networkId : -1;
代码示例来源: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: 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: TeamFatCat/Easy_Transfer
/**
* 连接热点
*/
public boolean connectionWifi(int ID) {
return mWifiManager.enableNetwork(ID, true);
}
代码示例来源:origin: JackWHLiu/jackknife
public void applyConfiguration(int index) {
if (index > mWifiConfigurations.size()) {
return;
}
mWifiManager.enableNetwork(mWifiConfigurations.get(index).networkId, true);
}
代码示例来源:origin: LiqiNew/MyUtils
/**
* 指定配置好的网络进行连接.
*/
@Override
public void connetionConfiguration(int index) {
if (index > mWifiConfigurations.size()) {
return;
}
// 连接配置好指定ID的网络
mWifiManager.enableNetwork(mWifiConfigurations.get(index).networkId,
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: 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
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: 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
内容来源于网络,如有侵权,请联系作者删除!