Barcodes and Android
Barcodes are very widely used and often contain a unique ID to identify a product, person or similar. They can also be used to store small pieces of information. This is very useful when it comes to Android.
There are a lot of different encodings for barcodes but the one we’re primarily interested in is known as QR Code. It’s a 2-D barcode which looks something like this:

Why are barcodes useful?
They provide us with a quick and easy way to transfer snippets of information (or instructions) to your Android phone.
There is a Google application in the Marketplace called Barcode Scanner. It uses the camera on your phone to act as a barcode reader. It supports a large number of formats.
There are other applications which allow you to display certain information from your phone as a QR Code barcode.
This allows you to display Contact, SMS, URL, Address, Geo Location, and other types of data on your screen in a machine-readable format.
From there, it’s simple to read them on a second device using the barcode scanner.
There are a number of actions on the pone which can be triggered using specially formatted URLs. The most useful of these (for me) is to locate applications in the Marketplace. For example:

market://search?q=pname:com.javielinux.apptoqr
When scanned with an Android phone will search the Marktplace for an application which which generates barcodes for every application on your phone.
I use a number of QR Codes in this blog – Each page has the current url in a QR Code. I also provide the market:// urls for any applications I mention
How can you use QR Codes?
The simplest answer it to take advantage of the Google ZXing (pronounced “Zebra Crossing”). Google has provided online tools to encode data as a QR Code and extract and decode QR codes from images.
If you have a Wordpress blog, you can get a plugin to easily insert QR codes into your posts.
Posting from my Android mobile
I’ve found an application called wpToGo which allows me to post directly from my phone. This is me testing it out.
wpToGo:

Taken Fri 23rd october
Attached is a photo taken outside my office.
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;
- 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.
- 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)
- Create additional directories for Keys, SDCards and Projects as shown
- Download and install MOTODEV Studio
- 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.
- Once installation has completed, select the option to launch MDS and click Finish.
- 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:
- 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.
- 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:
- 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.



