Is it normal to only have a broadcast intent with action NETWORK_STATE_CHANGED_ACTION
(whose constant value is android.net.wifi.STATE_CHANGE
) when a Wifi connection is coming back up? I.e. I don't get this intent when Wifi is being disconnected.
UPDATE: I am mostly interested to >= 2.2 Froyo
In android's API it says that it's not a good idea to check STATE_CHANGE for network connectivity and instead you should use SUPPLICANT_CONNECTION_CHANGE_ACTION. this will notice an establishment to a wifi network, and the disconnection of a wifi network. I don't know if this might help you, but I do hope so. LINK
I had a similar need in my project and ended up having to use both.
The android.net.wifi.supplicant.CONNECTION_CHANGE action sends a broadcast when the network is connected, but usually before the device has an IP address, so I needed the android.net.wifi.STATE_CHANGE action for that.
The android.net.wifi.STATE_CHANGE action receives a broadcast on disconnect only if the device is disconnecting from a network, but wifi is still enabled (when hotspot goes out of range, for example)
So you should put both actions for the receiver in the manifest:
and you put an if to check which action is being called in the intent. Here is the onReceive method of the BroadcastReceiver in my code: