I have Googled and find many sites saying about 'disabling Wifi radio'. But in my case, I just want the android device to disconnect from a specific wifi network(SSID preknown) without switching OFF the WiFi radio. Please give me some insights on this issue
Wow this shouldn't have taken a month to be answered.
Here's the easiest way that I usually use:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.disconnect();
discon = new DisconnectWifi();
registerReceiver(discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION));
Where DisconnectWifi is just a small class the extends BroadcastReceiver:
public class DisconnectWifi extends BroadcastReceiver {
@Override
public void onReceive(Context c, Intent intent) {
if(!intent.getParcelableExtra(wifi.EXTRA_NEW_STATE).toString().equals(SupplicantState.SCANNING)) wifi.disconnect();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With