2

I am trying to develop an application that connects some spesific wifi access points if it is available. I wroto a service that loops with 30 seconds interval and looks if these spesific wifi access points are available. I am concerning that it may consume the resources too much. I am thinking of a solution if there is any probability android WifiManager (or another utility) notifies my service about new wifi access points are available. It is like new wifi access point listener.

Is there any utility in android to achive this goal?

Alper
  • 771
  • 1
  • 9
  • 27

2 Answers2

2

You should bear this in mind that your android device regularly scans for WiFi networks when the WiFi radio is on. So you need not check for them manually. It will double the load on the OS.

You can set a listener for SCAN_RESULTS_AVAILABLE_ACTION within your service. It will notify you when the device finishes its regular scanning process. When you receive this broadcast, check all the access points to see whether your desired access point is available or not. However, you can only do this while your WiFi is ON. But its better to keep WiFi ON rather than continuously toggling it ON and OFF, especially when you do it at a small time interval of just 30 seconds, which would drain the battery much faster.

Vikram Gupta
  • 6,496
  • 5
  • 34
  • 47
  • 1
    I would like to ask the same question, what is regular time for this scanning? Do you have any idea on that. By the way thank you for your clear answer. – Alper Nov 02 '12 at 15:32
  • 3
    It depends on various factors: CPU speed, RAM, number of active tasks, depends from phone to phone. You can keep a check on your broadcast receiver and print the time. Normally its around 15 seconds (i checked it on LG LU3000 dual core) and varies a lot. – Vikram Gupta Nov 02 '12 at 15:47
1

You can see samples on the net. Your application can do something similar to http://marakana.com/forums/android/examples/40.html

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
  • I already applied this logic into my application. I need a notifier if a new wifi access point is available. If you carefully read my question, I need a little different approach. – Alper Nov 02 '12 at 11:45
  • You get notified by WiFi Manager upon scan results. You can store the latest scan results and compare them when a new list arrives. No need to loop or poll. The overhead is only from lists comparison. See here for more details: http://stackoverflow.com/questions/4253249/android-get-notified-when-a-new-access-point-is-detected – SomeWittyUsername Nov 02 '12 at 12:22
  • OK, I see your point, it seems that "SCAN_RESULTS_AVAILABLE_ACTION" works for my solution (it is just I do not have changing number of wifi aps, when I close my adapter and open it reciever takes the input). But I do not understand that part, what is the schedule for android broadcasts this signal? Is there a time interval for this scanning? Any comment on this? – Alper Nov 02 '12 at 15:29
  • @Alper scanning trigger might come both from the OS and from the WiFi driver itself. You can force the scanning interval to be whatever you need (as long as the hw and driver can withstand it). See here: http://stackoverflow.com/questions/7625071/what-interval-should-i-use-between-each-wifi-scan-on-android – SomeWittyUsername Nov 02 '12 at 17:21