Android: Weather Focus application
“Weather Focus”is a demo application I have put together. It fetches the seven day weather forecast based on your current geographical location (latitude, longitude).

Full project source code here.
APK file here.
The source of the weather data is the XML feed from NDFD here. I am not using the SOAP service just the straight xml API. Web services under Android are possible but it’s a lot more work than I was prepared to put in.
So, a quick rundown of the application
- Uses the alarm service to spawn a periodic background thread. This thread loads the weather data, parses it and writes it to a ContentProvider.
- Uses built in GPS to fetch current location. This is tagged onto the XML request URL.
- The parser is bog standard SAX based handler. Fast and lean.
- The ContentProvider is backed by SQLLite database.
- Synced columns in database to allow implementation of a ContentObserver which listens for changes to the database and updates the textual timestamp on the front of the application.
- ManagedQuery watches the provider and updates the master list.
- Weather icons are fetched remotely from the web service and cached locally. This avoids having to get the same icon again and again.
- Data is fetched periodically as long as the application is running. This is total overkill for something like weather data but this is purely a demo to show off how to do this.
- Notifications on the top bar of the phone view.
- Toast popups to indicate the starting and stopping of service.
Basically this was the same layout as my traffic application. I just switched it to weather data as I was getting bogged down trying to implement a fancy back end to that app. I will get back to it but I figured better to learn to walk before I run.
Notes
- If you modify the database you will have to set the version number constant to a different value to force the database to rebuild.
- Sometimes the XML weather feed returns less than seven days info. Strange!
- Sometimes the odd strange characters seem to appear instead of the proper weather description.No idea why, it’s coming from the feed and not the application.
I notice that this is quite like the HandWx weather application which has a similar forecast screen. The HandWx application also has radar weather data on the google map view. I’m not sure if that data is available across the xml service but I think it would be interesting to look. Will keep you posted.
Comments
Leave a Reply