Android - Correct way to detect disconnecting from a particular wifi ssid?

前端 未结 4 1991
梦毁少年i
梦毁少年i 2021-02-06 16:02

I\'ve seen a couple of BroadcastReciever examples to detect wifi disconnects but none of them seem to work correctly (triggering twice for each disconnect for example) and none

4条回答
  •  逝去的感伤
    2021-02-06 16:51

    I got the same problem in some custom roms. I used "android.net.wifi.STATE_CHANGE" to listen the network change. In the receiver, I used "(NetworkInfo)intent.getParcelableExtra("networkInfo")).getState()" to get the network state. There are three states: DISCONNECTED, CONNECTING, CONNECTED. You can use DISCONNECTED to detect if the network is disconnected.

    Please let me know if it works in your situation(HTC One X (4.1)).

提交回复
热议问题