12

I want to write an application which consists on perform actions when a known wifi networks get in or out of range.

For example, let's say my home wifi network's SSIS is "WifiHome", and i want to make a notification "You just left home!" whenever the device can't detect this specific network anymore. (Or alternativly - "You just entered home" when the device re-detect signals from this network).

My question is: Is is possible to listen to those changes without polling the available-network-list frequently?

StarsSky
  • 6,721
  • 6
  • 38
  • 63
Avi Shukron
  • 6,088
  • 8
  • 50
  • 84

1 Answers1

13

You should listen to broadcast event SCAN_RESULTS_AVAILABLE_ACTION. This will be sent each time Wi-Fi scan is finished. When such event occurs just re-iterate the scan results that can be obtained via WifiManager's getScanResults.

When wi-fi is active, you'll receive this broadcast every several seconds. But there is no way to configure this interval and my guess is that each manufacturer may change this interval.

You can manually trigger wi-fi scan using WifiManager's startScan.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • 1
    But if i dont want to scan manually, how frequently should i expect to recieve this broadcast? (in terms of seconds, lets say) – Avi Shukron May 12 '11 at 19:22
  • 1
    When wi-fi is active, you'll receive this broadcast every several seconds. But there is no way to configure this interval and my guess is that each manufacture may change this interval. I would recommend to introduce a setting X - "max delay between rescans". If you don't receive any scan results for X seconds, you'll force manual rescan. – inazaruk May 12 '11 at 19:39
  • OK. That's about it. one last question: Is there more specific event for "Current network disconnected"? – Avi Shukron May 12 '11 at 19:50
  • You should listen for NETWORK_STATE_CHANGED_ACTION. – inazaruk May 12 '11 at 20:02