android wifi 断开,Android ::如何从WiFi网络断开连接?

哇这不应该花一个月才能回答.

这是我通常使用的最简单的方法:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

wifi.disconnect();

discon = new DisconnectWifi();

registerReceiver(discon, new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION));

哪里DisconnectWifi只是一个小类扩展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();

}

}

你可能感兴趣的:(android,wifi,断开)