本文整理了Java中android.net.wifi.WifiManager.disableNetwork()
方法的一些代码示例,展示了WifiManager.disableNetwork()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.disableNetwork()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:disableNetwork
暂无
代码示例来源:origin: mayubao/KuaiChuan
/**
* 关闭当前的Wifi网络
* @return
*/
public boolean disconnectCurrentNetwork(){
if(mWifiManager != null && mWifiManager.isWifiEnabled()){
int netId = mWifiManager.getConnectionInfo().getNetworkId();
mWifiManager.disableNetwork(netId);
return mWifiManager.disconnect();
}
return false;
}
代码示例来源:origin: 18Gray/CommonUtils
/**
* 断开指定ID的网络
* @param netId
* @param context
*/
public void disconnectWifi(int netId, Context context)
{
wifiManager.disableNetwork(netId);
wifiManager.disconnect();
}
代码示例来源:origin: JackWHLiu/jackknife
public void disconnect(int networkId) {
mWifiManager.disableNetwork(networkId);
mWifiManager.disconnect();
}
代码示例来源:origin: LiqiNew/MyUtils
/**
* 断开指定ID的网络.
*/
public void disConnectionWifi(int netId) {
mWifiManager.disableNetwork(netId);
mWifiManager.disconnect();
}
代码示例来源:origin: qyxxjd/AndroidBasicProject
/**
* 断开指定ID的wifi
* @param networkId
*/
@RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE)
public void disconnect(int networkId) {
mWifiManager.disableNetwork(networkId);
mWifiManager.disconnect();
}
}
代码示例来源:origin: qyxxjd/BaseProject
/**
* 断开指定ID的wifi
*/
@RequiresPermission(Manifest.permission.CHANGE_WIFI_STATE)
public void disconnect(int networkId) {
mWifiManager.disableNetwork(networkId);
mWifiManager.disconnect();
}
}
代码示例来源:origin: DeviceConnect/DeviceConnect-Android
/**
* 指定されたネットワークが反映されているかをチェックして、接続を行う.
*
* @param networkId ネットワークID
* @param targetSSID 接続するSSID
* @return 接続に成功した場合はtrue、それ以外はfalse
*/
private boolean connectWifi(final int networkId, final String targetSSID) {
String ssid = targetSSID.replace("\"", "");
mWifiMgr.startScan();
for (ScanResult result : mWifiMgr.getScanResults()) {
if (result.SSID.replace("\"", "").equals(ssid)) {
WifiInfo info = mWifiMgr.getConnectionInfo();
if (info != null) {
mWifiMgr.disableNetwork(info.getNetworkId());
}
return mWifiMgr.enableNetwork(networkId, true);
}
}
return false;
}
代码示例来源: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: DeviceConnect/DeviceConnect-Android
/**
* 指定されたネットワークが反映されているかをチェックして、接続を行う.
*
* @param networkId ネットワークID
* @param targetSSID 接続するSSID
* @return 接続に成功した場合はtrue、それ以外はfalse
*/
private boolean connectWifi(final int networkId, final String targetSSID) {
saveWiFiSSID();
String ssid = targetSSID.replace("\"", "");
mWifiMgr.startScan();
for (ScanResult result : mWifiMgr.getScanResults()) {
if (result.SSID.replace("\"", "").equals(ssid)) {
WifiInfo info = mWifiMgr.getConnectionInfo();
if (info != null) {
mWifiMgr.disableNetwork(info.getNetworkId());
}
return mWifiMgr.enableNetwork(networkId, true);
}
}
return false;
}
代码示例来源: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;
}
内容来源于网络,如有侵权,请联系作者删除!