Question

I'm brand new to the android developer world. I'm working through a few books and some example programs to get my bearings. I have questions about an android app that I'd like to write.

My school has an open wifi network that is secured by a gatekeeper page that requires you to login with a username/password. Once a device is connected to the routers, any http request is redirected to the router-based login page. I want to automate this handshake.

I've so far figured that I'll rely on the android.net.wifi.ScanResult class. I'll want the app to check if the SSID matches the school's network, and if so, open a page to some user-specified home page where it'll be redirected to the sign-on page, enter the user info to complete the connection, and then quietly stop working.

I want to do this because, particularly with mobile devices set to have their wifi connection sleep on screen turn off, looking up simple things during class is infuriating. Either you turn off wifi and rely on a 3G connection or you have to type in your user/pass combo each time you want to look up a term.

What I need help with is this: I don't know how often the wifi scans. I don't want to write an app that monitors the connection at all times. I want it to check the wifi it's connected to when the user unlocks the screen. If it's the schools SSID I want the program to run and connect and then turn off. How do I achieve this simple login without unintentionally creating a battery hog that's doing way more than it needs to?

Thanks in advance and sorry for the verbosity. I'll get more concise when I understand better what I'm doing.

Was it helpful?

Solution

Thinking through how it'd be done you'd probably want a service run to monitor the state of wifi:

http://developer.android.com/reference/android/net/wifi/package-summary.html is a good starting point for an overview. http://developer.android.com/reference/android/net/wifi/WifiInfo.html & http://developer.android.com/reference/android/net/wifi/WifiManager.html#reconnect()

This would let you check the state. If it's not connected, reconnect() lets you connect. Using http://www.openintents.org/en/node/320 for Bluetooth but would be a good place to shove this. Next is the issue of authentication, that would probably best be done via a web view:

http://developer.android.com/reference/android/webkit/WebView.html

This will let you remote control the authentication, injecting a javascript file in to auto fill the user/password and submit it. See the near the end again for more info.

I'd also advise keeping it flexible storing your destination in an xml/sql file. For storing the password there's a lot of ways to crypt it Android SQlite password encryption? & http://code.google.com/p/openintents/source/browse/#svn/trunk/Safe for more information on that.

http://www.openintents.org/en/node/36 has a WebView example. http://lexandera.com/2009/01/injecting-javascript-into-a-webview/ and it's linking pages to http://jsharkey.org/blog/2008/12/15/oilcan-greasemonkey-on-steroids-for-android/ should help more with the javascript & webview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top