本文整理了Java中android.net.wifi.WifiManager.reconnect()
方法的一些代码示例,展示了WifiManager.reconnect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.reconnect()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:reconnect
暂无
代码示例来源:origin: robolectric/robolectric
@Test
public void reconnect_shouldNotThrowException() {
assertThat(wifiManager.reconnect()).isFalse();
}
代码示例来源: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: amap-demo/android-service-location
public static void startWifi(Context context) {
WifiManager wm = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
wm.setWifiEnabled(true);
wm.reconnect();
}
代码示例来源:origin: steinwurf/adb-join-wifi
@Override
public void run() {
mWifiManager.disconnect();
try
{
while(!isInterrupted())
{
Log.d(TAG, "Joining, network id=" + Integer.toString(finalNetworkId));
mWifiManager.enableNetwork(finalNetworkId, true);
mWifiManager.reconnect();
// Wait and see if it worked. Otherwise try again.
sleep(10000);
}
} catch (InterruptedException ignored) {
}
}
};
代码示例来源:origin: gizwits/GOpenSource_AppKit_Android_AS
boolean enabled = wifiManager.enableNetwork(netID, true);
Log.d(TAG, "enableNetwork status enable=" + enabled);
boolean connected = wifiManager.reconnect();
Log.d(TAG, "enableNetwork connected=" + connected);
代码示例来源:origin: stackoverflow.com
boolean enableNework(String ssid, Context cxt) {
boolean state = false;
WifiManager wm = (WifiManager) cxt.getSystemService(Context.WIFI_SERVICE);
if (wm.setWifiEnabled(true)) {
List<WifiConfiguration> networks = wm.getConfiguredNetworks();
Iterator<WifiConfiguration> iterator = networks.iterator();
while (iterator.hasNext()) {
WifiConfiguration wifiConfig = iterator.next();
if (wifiConfig.SSID.equals(ssid))
state = wm.enableNetwork(wifiConfig.networkId, true);
else
wm.disableNetwork(wifiConfig.networkId);
}
wm.reconnect();
}
return state;
}
代码示例来源:origin: LiqiNew/MyUtils
/**
* 连接wifi(有密码).
*
* @param ssid 热点名
* @param strPSW 热点密码
*/
public void connect(String ssid, String strPSW) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = "\"" + ssid + "\"";
config.preSharedKey = "\"" + strPSW + "\"";
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.status = WifiConfiguration.Status.ENABLED;
int netId = mWifiManager.addNetwork(config);
mWifiManager.disconnect();
mWifiManager.enableNetwork(netId, true);
mWifiManager.reconnect();
}
代码示例来源:origin: LiqiNew/MyUtils
/**
* 连接wifi(无密码).
*
* @param ssid 热点名
*/
public void connectNoPwd(String ssid) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = "\"" + ssid + "\"";
config.preSharedKey = null;
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.status = WifiConfiguration.Status.ENABLED;
int netId = mWifiManager.addNetwork(config);
mWifiManager.disconnect();
mWifiManager.enableNetwork(netId, true);
mWifiManager.reconnect();
}
}
代码示例来源: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
代码示例来源: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
wifiManager.disconnect();
wifiManager.enableNetwork(networkID, true);
wifiManager.reconnect();
代码示例来源:origin: stackoverflow.com
_wifiManager.startScan();
_wifiManager.reassociate();
_wifiManager.reconnect();
代码示例来源:origin: stackoverflow.com
wifiManager.disconnect();
networkOnePresent = wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
Log.d("wifi", "net id is = "+netOneId);
break;
代码示例来源:origin: stackoverflow.com
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
代码示例来源: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;
}
代码示例来源: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.disconnect();
wifiManager.enableNetwork(netId, true);
wifiManager.reconnect();
try {
waitForWifiConnectivity();
内容来源于网络,如有侵权,请联系作者删除!