简体   繁体   English

并非总是在wifi切换时触发android.net.wifi.STATE_CHANGE

[英]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. 我有2个路由器发出具有相同SSID的wifi,并且我基本上希望我的应用实时告诉我“我已连接到路由器X”。 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. 我有一个android.net.wifi.STATE_CHANGE的广播接收器,如果我连接到任何一个wifi或从其中任何一个断开连接,都会按预期触发,并且可以适当地更新我的应用程序的显示。

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. 但是,如果我强迫我的设备从routerA跳到routerB(例如,当我连接到RouterA时拔掉routerA),则android.net.wifi.STATE_CHANGE不会总是触发。 sometimes it's triggered immediately (as expected) and reports "disconnect from testwifi on routerA" quickly followed by "connect to testwifi on routerB". 有时,它会立即触发(如预期的那样),并迅速报告“与routerA上的testwifi断开连接”,然后报告“与routerB上的testwifi连接”。 sometimes it's triggered after 30+ seconds. 有时会在30秒钟后触发。 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? 我觉得应该总是触发它,因为两个wifi都有不同的BSSID,所以wifi状态正在改变...这是一个Android错误吗? 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. 弄清楚如何得到我想要的东西,尽管我仍然不清楚这是否是一个Android bug。 so basically, the key is to listen to 所以基本上,关键是要听

android.net.wifi.supplicant.STATE_CHANGE android.net.wifi.supplicant.STATE_CHANGE

(ie, WifiManager.SUPPLICANT_STATE_CHANGED_ACTION) rather than (即WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)而不是

android.net.wifi.STATE_CHANGE android.net.wifi.STATE_CHANGE

(ie, WifiManager.NETWORK_STATE_CHANGED_ACTION). (即WifiManager.NETWORK_STATE_CHANGED_ACTION)。 this android doc page gives an idea of what a supplicant is and why this solution works. 这个android doc页面给出了一个请求者的概念以及为什么该解决方案起作用的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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