Getting Started

I’ve recently started developing for my new android Phone (The T-Mobile G-1, currently running Android 1.5 (Cupcake)) . After writing a few applications I decided to keep a record of my discoveries and so I created this blog.

I’ve read blogs for years but never had my own so any tips, tricks or hints would be greatly appreciated.

Ok…

Before we dive in, let’s have a quick look at how the Android powered phones work

According to the documentation;

Android is a software stack for mobile devices that includes an operating system, middleware and key applications.

The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

So, we’ve got an application framework which is Java-based and running on Linux. This allows us an enormous amount of flexibility whilst also giving us a consistent, managed environment in which to develop.

Google and Motorola have both provided IDEs which will allow you to work far faster than a standard text editor. (Installation instructions below)

There is one consideration when developing for Android which you may not be used to:

As we’re developing for a mobile platform, performance and resource usage is critical.  We’ll have limited RAM, a light-weight CPU, the Dalvik VM interpreting code (which adds a considerable CPU overhead) and finally,. the more work we do, the more battery we use.

All of the above combine to make resource usage one of your top considerations. If your application is going to run when the user isn’t actively using the phone, you should try to use an event-driven model rather than polling. This way, you only use battery when you need to respond to an event.

In short, if you’re using more battery than the user would expect, they’re likely to uninstall your application.

More information about Android performance can be found here

What can Android applications do?

Android applications can specify which permissions they require when they are installed. The following list assumes your app has been granted the appropriate permissions:

  • Read information from phone sensors – Location, orientation, network signal, etc…
  • Intercept inbound call, email and SMS events
  • Generate outbound Emails, SMS and calls
  • Access the internet
  • Read data exposed via contentProviders (Contacts, Call history, etc…)
  • Play multimedia using native codecs (More info here)
    • Audio: MP3, AAC, AAC +, WMA, WAV, MIDI, REAL AUDIO, OGG
    • Video: H.264, 3GPP, MPEG4, and Codec 3G
  • Run in the background (This is a huge advantage over the iPhone)
  • Display a UI

What can’t Android applications do?
Unfortunately, there are some things which you simply cannot do with the standard android environment. I’ve only found a couple so far but I’ll add more here as I find new ones.

It’s worth noting that most of these are not possible for a good reason – Android is a very robust environment which prevents applications from performing actions which could impair overall device usage.

The development environment

Fortunately, the documentation provided by Google is first-class so please do reference it as an when required.

First of all, we need to get some tools. You have 4 options:

  • Use eclipse with the android SDK.
  • Use MOTODEV Studio
  • Manually integrate into a different IDE
  • Command-lines and scripts.

I played around with options 1, 2, and 4.  MOTODEV Studio is also eclipse-based and includes all the functionality of the andoid SDK as well as adding some additional functionality. It’s very easy to develop with and will save you a lot of time.

Although the command line is not often required if you’re using MDS, it’s useful to have a quick look over the developers guide pages so you’re aware of what is possible.

Assuming you’re going to use MOTODEV Studio;

  1. Download the Android SDK

    Create an Android folder in an easy to access part of your disk. As I’m on windows, I chose C:\Android.

    1. Extract the SDK to a sub-folder as shown on the right. I chose to use the SDK version as the folder name (1.6)
    2. Create additional directories for Keys, SDCards and Projects as shown
  2. Download and install MOTODEV Studio
    1. This installation is fairly straight-forward. If you do not have the appropriate software (JRE, SDK) installed on your system already, the installer will prompt you to install it.
    2. Once installation has completed, select the option to launch MDS and click Finish.
    3. When MDS launches for the first time, it will ask you to provide it with the location of the android SDK. Direct it at the folder you created in Step 1:
    4. When prompted, choose the option to create an AVD (Anddroid Virtual Device). This is a fully functional device emulator which will allow you to test your applications without the need of a phone plugged into your PC.
    5. You can have multiple AVDs configured at any time but for the moment, we’ll set up one device which will run the 1.5 (Cupcake) version of Android. (I’ve picked 1.5 as not all phones have had the 1.6 Donut patch yet). Name your AVD something appropriate and continue:
    6. Next, we’ll configure the new device. Most settings can be left at their defaults for now.One important step to take is to create a new SD Card image. This is the physical file on your machine that will represent the SD Card inserted into the virtual device. I’d recommend a size between 512M and 2GB

And that’s it, you’re done! You now have a fully functioning development environment.

Distributing applications

Each application is distributd in a single .apk (Android package) file. This is a compressed file which contains the application manifest, the application itself and any other resources required by the application (layouts, images, etc…). You can manually inspect these files using your favorite zip program – Personally, I prefer WinRAR.

By default, Android will only install applications from the Android Marketplace.  This won’t be an issue on your virtual device but when you get to using a real phone, you’ll need to go in to the security settings and enable installation from “Untrusted Sources”.

Incidentally, this is one of the major differences between Android devices and the iPhone – iPhones will only install applications from the Apple Application Store (and their inclusion quidelines are the subject of some debate). This is what made me choose Android in the first place.

Sample Code
Google provide an excellent set of examples. I’ll be covering points from most of them in future postings. For the time being, you may wish to explore them yourself.