Sunday, June 3, 2012

SAWACE - SAWINFO Monitor - My First Android Application


INTRODUCTION
Mobile app development is not a new fad. But with growing popularity of android mobile operating system mobile app development is reaching to more and more developers. Earlier in one of my blog I had developed a mobile application for Windows based mobiles [ iMateBuddy ]. Though professionally I'm working on Microsoft Technologies, but I wanted to try my hand at android application development using java. So as soon as I bought my first android mobile I was very eager to develop my own android app. 

SAWACE Android App  powered by sawinfotech.com

App settings page to set url to hit. Start button starts the service.
Website UP notification. Notification detail page.
click the images to enlarge +

The Idea Behind
Nowadays android app for almost everything is available on Play Store. So what new could I create that was not there already and was very personalized. After giving some thought to what android app I should build I decided on creating a Website Monitor for my site. Why? I'm hosting my website www.sawinfotech.com from a VM hosted on my home desktop. And although its protected against occasional power failure by a UPS, intermittently the fail-over to UPS is delayed sometimes and due to which desktop power downs, in turn shutting down the VM and in turn the site goes down. I would not come to know of this down time until I access the site next time which could sometimes be more than a day or two. So I though of building a mobile app which would run as a service and would periodically hit my site to check if it is up or not and give the notification accordingly.

Application Details
So with this idea in mind I created a app which is quite simple. Basically it hits a URL of sawinfotech.com periodically (every 8 hrs)  and gives a notification if the site is Up or Down. The URL is configurable and can always be changed through Settings screen. To change the URL we just have to stop the service, change the URL and start the service again. Short and simple. Following are some code snippets.

Home Class

































Above class handles the initial loading of the Settings page and the event handlers for Starting and Stopping the service.

Service Class


































This class is the heart of the app which runs as a service which is invoked periodically. The function of the service is to hit the configured URL of my site sawinfotech.com to check if the site is up.


Notification Class



















The Notification class is used to generate the notification to show the user if the service return of success message in case the website is up or a failure message if the site is down.

AndroidManifest.xml














Manifest file is configuration file similar to web.config of asp.net. Here we list all the Activity classes (screens), Service classes, user permission etc. For this app I have used permission for internet access. One more thing we can configure is here is to set which Activity/Screen is the loaded at startup of app.

Code is quite self explanatory. If any queries please add comments and I'll try to answer to best of my knowledge.

Just FYI, my blog is not sponsored by Samsung :)

s.a.w