Wednesday, August 29, 2012

Programming a vibrational alarm for Android, HourlyReminder App

I was looking for some cron like command in android to make google nexus 1 vibrate in certain pattern (GOD in Morse Code :) for certain time. After a lot of googling, i found many resources to make this happen :) But it was not as straight forward as i thought...

Basically one needs to use android's AlarmManager to make it all work. Difference being that cron executes a command, while AlarmManager broadcasts an Intent and it will make your code do the magic when the alarm goes off :). BroadcastReceiver registered in your manifest takes this and runs when you reboot the system. One tricky thing is that you have to make sure that AlarmManager wake up the device in anticipation of alarm... God knows why! But this can be done via the WakeLock using PowerManager system service (make sure to add it in manifest!). Also one other critical thing is to force the system not to use SD via manifest.

There are many threads on stackexchange talking about all this, from where i shamelessly mashed up my code. It is available in the src/xml files of If you would like to check out the app, it has been loaded at :)

No comments: