Adding an alarm to Android Alarm clock

If you need to set an alarm from within your application, you might be guided to the android AlarmManager. While it’s possible to use the AlarmManager to fire an alarm, sometimes you want to use the alarm application the user has installed himserver.

To do so, you can use AlarmClock.

This can be done in the following way:

You’ll need to add the right security permission to your manifest though:

A small note: there’s no way to cancel the alarm after the intent has been sent. If you need more control over your alarm, you’ll need to to use something like the AlarmManager anyway, which provides more control over your set alarm, like cancelling.

This week in Discobot (40.2011)

After some hectic times at work caused by very tight deadlines and me getting married in the beginning of September we finally managed with Erik to get back to working on Discobot last week.

Some of you have probably already noticed that we have a talk on Discobot scheduled at Groovy & Grails Exchange 2011 in London which takes place in early December. Although the progress is good there is still quite a lot of work to be done on Discobot and we decided that probably one evening a week will not be enough. On the other hand knowing about the talk gives us an even stronger motivation to succeed!

Last week Erik continued his work on getting all Groovy tests running in the emulator. We found out that ‘on the fly generated’ classes which are created by Groovy when you for example cast a map of closure into a class using ‘as’ keyword cannot be loaded by the classloader. The reason is simple – classloader looks for class files but it should be looking for dex files. This is our main concern at the moment as it causes exceptions all over the place and breaks anything more complex than a ‘hello world’. From the code written by Hjalmar we’ve noticed that he also encountered the problem and we’re trying to apply his solution to see if it will work. So, it looks like there’s a lot of class loading fun ahead of us!

We’ve also got a response from guys behind Gradle plugin for Android about our pull request. They had several small remarks which I managed include in my second pull request. From what they said it looks like they should accept it in the coming days.

I’ve also looked for options regarding a repository in which to put our artefacts (Gradle plugin and the modyfied version of Groovy). I’ve found a nice blog about creating a a github based Maven repository and using it with Gradle. It seems easy and straightforward so probably we will go for this solution for now.

This (two) week(s) in Discobot (30-31.2011)

Each week, we work on the Discobot project, which goal it is to make Groovy run on Android. While that in itself isn’t the biggest problem, as you can read in our previous blog posts, making developing for Android using Groovy and making sure we are feature complete, well, let’s say it’s challenging.

Current efforts are twofold: one is developing a set of developer tools using Gradle, on which Marcin is focusing the most. On the other hand, we need some tools to make sure our version of Groovy works on Android, which is what I (Erik) am focusing on.


As you can see in the screenshot above, our project is already capable of building the project and installing it on the emulator using the Gradle plugin. Also, the start of a demo application has been built, which will allow us to run all the tests packed with Groovy. For that, we have tweaked the build process of Groovy itself, so that it produces a jar which includes all the tests. This jar is used in the Discobot project. To figure out which tests are available, an Android Classpath Scanner is used. It uses a hack by inspecting the Dex files itself, but we are currently using that to scan for files which extend from GroovyTestCase, and run those. Once that is working, we’ll probably write a better UI around it.

Also, the Gradle plugin still needs some finishing touches to improve the overall user experience. Marcin is currently working on the last gradle task which will initialize the android project structure. It will call the android create project command-line tool from Android SDK, change the src directory structure of your project to obey Gradle conventions and create a ‘Hello World’ activity written in Groovy, so you can quickly get a simple working application to start out with!

We’ll try to update you again with more information next week!

This (two)week(s) in Discobot (27-28.2011)

We continued our work on getting Groovy working on Android over the past two weeks.

Erik has made quite a good progress with the tests suite for Discobot. What he has achieived by now now is a slightly modified original Groovy test suite running against the compiled but not packaged (jared) code of our patched version of Groovy on his laptop. And of course it’s all green! As we removed some unnecessary classes and had to patch other, because the Dalvik VM doesn’t provide all the classes that regular Java does, Erik also had to remove and change some of the tests but we are trying our best to keep the needed patching to a minimum. It all looks promising and the next step for Erik is to run the tests against a jar and then create an Android app that will run all the tests on the emulator/device. We need that to learn if the differences between Dalvik and regular Java will break any tests and we can do that only by running the tests on a real Dalvik VM. This will give us some confidence that when people start using Discobot for something more complex than a ‘Hello World’ app things won’t start to break big time.

One of the concerns when Hjalmar Ekengren started his first efforts to run Groovy on Android as his GSoC project was the performance. I recall him telling me that it took up to 20s to start even a really simple app back in 2009 in the emulator. Apparently the things have improved quite a lot and our simple ‘Hello world’ example loads in the emulator in less than 5 seconds. It’s still quite long in my opinion. But last week when I uploaded our test application to my HTC Desire running Android 2.2 I was really surprised how quick it loaded the app – I think it’s less than a second! So we don’t have to worry about the performance, at least at this stage of the project.

For the past two weeks I worked hard on modifying the Android Gradle plugin and creating the Discobot Gradle plugin. Thanks to the extensive documentation that the Gradle project has and a terrific example in the original Android Gradle plugin it wasn’t hard to understand Gradle concepts. And when you get the main principles of Gradle it’s a real pleasure to work on a Gradle plugin.

I’m basically done with all the changes that had to be made to the Android Gradle plugin so that the Discobot Gradle plugin could extend it and use it for its own needs. The last thing I need to work on is the documentation – the changes I’ve made are breaking for the Android Gradle plugin and I think that if I update the docs the developers of that plugin will be happier to accept my pull request. I tried to contact the github repository owner of the Android Gradle plugin (Jason Voegele) before I started the work on it to learn what is his view on the changes I planned to make but unfortunatelly I didn’t get a response to my email. Hopefully when I create the pull request someone will get it processed…

Also the Discobot Gradle plugin is almost ready. Currently it builds the Android projects that use Groovy without a problem. I still want to add one task to it that will create the project structure and default files (AndroidManifest.xml and the main activity class among others) so that it will be easier to start the project from complete scratch with only a build.gradle file in your project. The task, updating Gradle Android plugin’s documentation and creating a pull request on my changes are my goals for the next week.

This week in Discobot (26.2011)

Currently, we (Erik Pragt and Marcin Erdmann) are working on getting Groovy to run on Android and make the process as smooth as possible for other developers. On this blog regular updates will be posted to inform you about the progress we made, the problems we ran into and how we solved them. This is the first episode of ‘This week in Discobot’. Read more