Skip to main content

Hello Android!

Android

Last month I bought my first new mobile phone since 2001 (honest).

As a developer I wanted something I could play with, so after looking at the iPhone, Blackberry and Windows based offerings I ended up going for the HTC Magic running Google's Android platform.

So far, I've found it to be a fantastic phone: easy to use, lots of very cool features and small enough to fit in your pocket. It's definitely on a par with Apple's OS (I own an iPod Touch) – and with other Android devices coming to market it looks like Google is onto a winner (again).

There are several fantastic applications available for Android phones. Two of may favourites are GeoBeagle and Wikitude – World Browser (both available in the Marketplace).

GeoBeagle

GeoBeagle is an open-source Geocaching application. What is Geocaching..? As the website explains:

"Geocaching is a high-tech treasure hunting game played throughout the world by adventure seekers equipped with GPS devices. The basic idea is to locate hidden containers, called geocaches, outdoors and then share your experiences online. Geocaching is enjoyed by people from all age groups, with a strong sense of community and support for the environment."

As Android phones come with GPS (Global Positioning System) built it – just like the SatNav in your car – they can be used to determine your location and how far away you are from a cache. GeoBeagle is an excellent application that makes this easy – and it's what I use when I go geocaching with my kids.

Wikitude

Wikitude World Browser is an example of augmented reality. I'll let their website explain,

"[It] presents the user with data about their surroundings, nearby landmarks, and other points of interest by overlaying information on the real-time camera view of a smart-phone."

When colleagues have asked about my new phone this is the one application I always show quite simply because it raises such incredulity and positive feedback that it is hard not to feel like a time-traveller from the future demonstrating a gizmo from Star Trek.

Happily, Mobilizy, the creators of Wikitude, have released an API (currently in closed Beta) and I requested to get on board. My intention was to mashup GeoBeagle and Wikitude as a means of learning Android development.

Yesterday evening I started experimenting. This evening I finished it off and managed to find enough time before sunset to run to my nearest geocache for testing, the results of which can be seen in the video below:

What does this show..?

  1. The freedom to learn from open-source projects such as GeoBeagle is invaluable for a newcomer to a platform such as Android. Bottom line: being open is an immediate win.
  2. Wikitude is an amazingly simple API to use. As you'll read below, the Mobilizy guys have made developer's lives very easy – my only concern being that such a simple API will make customisation difficult (although this is only the very first Beta release – I'm mentioning this for the purposes of feedback and fully expect Wikitude to mature).
  3. The Android platform is incredibly easy to learn, use, develop against and deploy to.

How..?

My background in software development includes C/C++, C#/.NET and Python. Android applications are written in Java and deployed to a Dalvik virtual machine – a "sandbox" for running Java especially designed for mobile devices. As a result I didn't know what to expect. I got from nothing to the content of the video above with the following steps:

Step 1

You'll need to download and install the Android SDK. Full instructions can be found on Android's developer site. This will probably involve installing and configuring the Eclipse IDE. Don't worry, the instructions are very clear and I managed to do it… ;-) (Also, the Android developer site is excellent with lots of tutorials, documentation and videos for the hungry mind.)

Step 2

Once you have the basic development environment installed you'll probably need to tweak it and check it with a simple "Hello World" application. In my case I needed to make sure that Eclipse was targeting Java 1.6 (I'm on OS X where Java 1.5 seemed to be the default choice). I bought an e-book version of Hello, Android and chugged through the opening chapters happy that things seemed to be building and working as expected. I also made sure I could deploy / develop against my "real life" mobile phone (rather than the emulator provided). This simply involved plugging it into the computer. You'll need to go to Settings -> Applications on your phone and make sure "Unknown Sources" is checked and that the appropriate settings are ticked under "Development" (I have "USB debugging" and "Stay awake" both checked).

Step 3

Get hold of GeoBeagle. The website's wiki has excellent instructions but you need to be aware of the following:

  • You'll need to have Subversion installed in order to get the source.
  • Don't use the "trunk" as suggested in the documents. Use the "sng" branch. Grab the code by issuing the following command:



svn checkout http://geobeagle.googlecode.com/svn/branches/sng GeoBeagle



  • Follow the instructions on the wiki but be aware that you'll have to make sure the di, gen and src directories are all referenced in the project's build path (Properties for GeoBeagle -> Java Build Path -> Source).
  • The same goes for when you set up the unit tests. I found that the Android 1.5 jar wasn't referenced in the Libraries section of the unit test project's Build Path configuration.
  • I could only get GeoBeagle to run on my phone, not in the emulator. I'm assuming the lack of appropriate hardware emulation (such as GPS) is the problem here. In any case, developing on a "real" phone is a breeze.

Step 4

Sign up for the Wikitude Beta programme and wait for the code and documentation to arrive via email. To get Wikitude and GeoBeagle to play nicely together I simply did the following:

  • Reference wikitudearintent.jar in the Libraries section of the Java build path for GeoBeagle.
  • Add an appropriate button (I put mine in the menu for the cache list) and join up the event handling code.
  • In the event handling code do something like this:



// create the intent

WikitudeARIntent intent = new WikitudeARIntent(myActivity.getApplication(), null, null);

// add the POIs (points of interest)

Collection<WikitudePOI> pois = new ArrayList<WikitudePOI>();

for(GeocacheVector gv : this.mGeocacheVectors.getGeocacheVectorsList()){

        Geocache geocache = gv.getGeocache();

        float longitude = (float) geocache.getLongitude();

        float latitude = (float) geocache.getLatitude();

        String name = (String)geocache.getIdAndName();

        String description = "A description - grab info from geocache instance";

        WikitudePOI poi = new WikitudePOI(latitude, longitude, 0, name, description, null, null);

        pois.add(poi);

    }

    intent.addPOIs(pois);

}

// Add a title

intent.addTitleText("Augmented Reality View");

// Launch the intent

myActivity.startActivity(intent);



There are only two types of object a developer need worry about:

  1. WikitudeARIntent – the "intent" for the Wikitude World Browser (in Android an "intent" represents something that does a specific sort of thing – like display information using augmented reality as in this case).
  2. WikitudePOI – a Point Of Interest to display with the Wikitude intent. You supply information such as the longitude / latitude, altitude, name, description and so on.

I'm sure the code example above and description of the two classes is more than enough to see how the API works. Even the Wikitude documentation is only three pages long (as it doesn't need to be any longer).

As I mentioned earlier, my main concern is that with such simplicity comes a lack of potential for customisation. For example, it would be great to override the menu that pops up if you double-tap a POI (as mistakenly happens in the video). Also, I'd like to be able to define area as well as individual points. Why? Consider the following use-case: wouldn't it be great to be standing at the top of the Eiffel Tower and look down on Paris with all the various neighbourhoods highlighted and perhaps colour coded (indicating traffic congestion, for example)?

Wrapping Up…

Many thanks to Stephen Ng whose advice and patient help was most gratefully received when trying to get GeoBeagle to build. Without open-source developers like Stephen great tools like GeoBeagle would never exist. He's worth his weight in gold! ;-)

Over the past two evenings I've had a lot of fun. I suppose the reason for this is both applications share the same outlook expressed in Wikitude's tag-line:

"The World IS the Platform!"

...and who wouldn't want to develop for that platform..?