1

I am trying to build an application/service that will execute some coding everytime I connect to a specific wifi network (to log into that network and then keep the connection active ). I do already have the code for the login part and it is working fine, but I don't really know how I can automatically run this code when I connect to a network.

Ideally, I would like to build a service that starts when I join a specific wifi network, keeps the connection active (like makes a request every 10 min to keep the connection active) and finally stops when I leave that network.

I know how to build the service and keep it active, but don't know how to start and stop it automatically when joining / leaving a wifi network. Any suggestions on how to do this is appreciated. If my approach is not correct and there is a better/simpler way to do that, please let me know

Regards,

Marcel

marcel f
  • 288
  • 2
  • 15

2 Answers2

0

you need a broadcast receiver. this broadcast receiver will receives broadcasts of Wifi connected and wifi disconnected actions and from there you can start and stop your service.

Budius
  • 39,391
  • 16
  • 102
  • 144
  • Thanks for the suggestion, registering a broadcast receiver on "android.net.conn.CONNECTIVITY_CHANGE" did the trick. I then use a WifiManager to get the SSID and start my service. – marcel f Aug 16 '12 at 09:51
0

Implement a BroadcastReceiver listening for the scan results from WifiManager.startScan()

Have a look at Android Scan for Wifi networks

Community
  • 1
  • 1
prayagupa
  • 30,204
  • 14
  • 155
  • 192