Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

android - WifiManager.getScanResults() - clarifications (automatic scans, sleep etc)

I would like some clarifications on the behavior of WifiManager.getScanResults(), namely :

When wireless is enabled

  1. Does android scan for access points on a fixed interval ? Can one query/change the interval ? Can one query the time of the last scan ? For a discussion see this answer
  2. What happens when the wireless radio is turned off (sleeps) - while wifi is still enabled - will getScanResults() go on returning the last scan results ? How would one know if it's time for startScan()?

When wireless is disabled

  1. getScanResults() would return the last scan results ? Or an empty List ? Or null (it does return null at times and this is not handled by 90% of the snippets posted in SO) ?
  2. The answer to 1 would be true even after a reboot (the phone booting with wifi off) ?

The reason I ask is I need to get the list of the available access points periodically and I'd rather call getScanResults() at once, than WifiManager.startScan() and then getScanResults() if I really do not have to - as this involves acquiring wifi locks and the like and is rather subtle. I am not also sure how much do the API level and phone hardware come into play.

For a good discussion of difficulties see this answer

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When wireless is disabled

  1. getScanResults() will return null...
  2. ...even after a reboot (that's to be expected - this would be disputed if it did not return null in the first place)

When wireless is enabled

2.Surprisingly enough getScanResults() will return null after some time (on a Nexus One, Android 2.3.7, Cyanogen mod - but I suspect this is not really relevant). So yes, apparently one has to initiate a scan irrespective of the wireless status

I guess this is true also if the state is WIFI_STATE_DISABLING

I am still interested in the answer in the case wireless is enabled - in particular question 2, if the device is asleep. Google groups won't let me post (hint)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...