简体   繁体   中英

android.net.wifi.STATE_CHANGE not always triggered on wifi handoff

i have 2 routers emitting wifis with the same SSID and i basically want my app to tell me "i'm connected to router X" in real time. i have a broadcast receiver for android.net.wifi.STATE_CHANGE that gets triggered as expected if i connect to or disconnect from either one of my wifis, and that updates my app's display appropriately.

however, if i force my device to jump from routerA to routerB (eg, by unplugging routerA while i'm connected to it), android.net.wifi.STATE_CHANGE is not always triggered. sometimes it's triggered immediately (as expected) and reports "disconnect from testwifi on routerA" quickly followed by "connect to testwifi on routerB". sometimes it's triggered after 30+ seconds. sometimes it's just not triggered.

i feel like it should always be triggered since both wifis have different BSSIDs and so the wifi state is changing... is this an android bug? am i missing something?

thanks!

figured out how to get what i want although it's still unclear to me whether this is an android bug or not. so basically, the key is to listen to

android.net.wifi.supplicant.STATE_CHANGE

(ie, WifiManager.SUPPLICANT_STATE_CHANGED_ACTION) rather than

android.net.wifi.STATE_CHANGE

(ie, WifiManager.NETWORK_STATE_CHANGED_ACTION). this android doc page gives an idea of what a supplicant is and why this solution works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM