本文整理了Java中android.net.wifi.WifiManager.disconnect()
方法的一些代码示例,展示了WifiManager.disconnect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WifiManager.disconnect()
方法的具体详情如下:
包路径:android.net.wifi.WifiManager
类名称:WifiManager
方法名:disconnect
暂无
代码示例来源:origin: cSploit/android
private int performConnection(final ScanResult ap, final String key){
mWifiManager.disconnect();
代码示例来源: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: leavesC/WifiFileTransfer
/**
* 断开Wifi连接
*
* @param context 上下文
*/
public static void disconnectWifi(Context context) {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null && wifiManager.isWifiEnabled()) {
wifiManager.disconnect();
}
}
代码示例来源:origin: LiqiNew/MyUtils
/**
* 断开指定ID的网络.
*/
public void disConnectionWifi(int netId) {
mWifiManager.disableNetwork(netId);
mWifiManager.disconnect();
}
代码示例来源: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: luhaoaimama1/zone-sdk
/**
* 断开当前网络
*/
public boolean disconnectWifi() {
// 断开指定的 wifi连接
// mWifiManager.disableNetwork(wcfg.networkId);
// 断开当前wifi的连接 一个意思
mWifiInfo=mWifiManager.getConnectionInfo();
if (mWifiInfo == null) {
System.out.println("当前没有网络连接 故不用断开~~~");
return true;
}
return 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: zplesac/android_connectionbuddy
@Override
public void onReceive(Context context, Intent intent) {
// unregister receiver, so that we are only notified once about the results
context.unregisterReceiver(this);
NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (listener != null) {
if (networkInfo.isConnected() && wifiManager.getConnectionInfo().getSSID().replace("\"", "").equals(networkSsid)) {
listener.onConnected();
} else {
if (disconnectIfNotFound) {
wifiManager.disconnect();
}
listener.onNotFound();
}
}
}
}
代码示例来源: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: 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 = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int networkID = wifiManager.addNetwork(getConnectionConfig(context, YOUR_SSID));
wifiManager.disconnect();
wifiManager.enableNetwork(networkID, true);
wifiManager.reconnect();
代码示例来源:origin: stackoverflow.com
Log.d("wifi", "wifi SSID is = "+i.SSID);
if(i.SSID != null && i.SSID.equals("\"" + SSID + "\"")) {
wifiManager.disconnect();
networkOnePresent = 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
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + networkSSID + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
代码示例来源: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();
内容来源于网络,如有侵权,请联系作者删除!