logo

Getting More Advanced With Android

Yesterday I talked about getting started with Android dev. The result of that exercise was to get a working demo of the various APIs at your disposal. With the source to each demo handy you can easily go and plug the bits together to realise your end goal. The next big thing, right?

As a standalone app though the ApiDemo is useless. Not only because it doesn't do anything, but mainly because it's not built like a real app and so you can't learn from it how you'd build a proper app.

When I'm getting to grips with a new platform the first thing I want to look at is a real-world application. Something built be experts using patterns and methodologies accepted as the best.

Luckily for us Android is open source.

You can browse the entire source of the latest stock Android build here. If you Look towards the bottom of that page you'll see packages in the folder "platform/packages/apps/". Notice there are apps called Email, Calendar, Camera and many others.

Getting Advanced

One of my pet projects is an app which is built around taking photos. Obviously it needs to use the devices camera. While there's a "camera output" demo in the ApiDemos app it's by no means a working camera application. Far, far from it.

I'd started trying to write my own camera app from scratch, only to realise I was re-inventing a massive wheel. A massive and complicated wheel. Then I twigged - "Hang on a minute!", I thought, "if Android is open source and it has a camera app built in surely I can use it as a starting point?!". Turns out I could. Here's how.

First thing I did was download the stock Android camera app's GIT package. To do this I used my Mac (you can do it on Windows with 3rd party software but OSX can do it already).

At the Terminal I typed in the following command:

git clone git://android.git.kernel.org/platform/packages/apps/Camera.git

It then downloaded the app in to a folder called "Camera" on my Mac:

image

Next step - I moved the Camera folder over to my Windows machine where I've got Eclipse and do most of my dev work. I placed it inside the "workspace" folder for Eclipse (normally in the C:\Users\YourName\ folder).

Next I launched Eclipse and chose File -> Import... and then chose "Existing Projects in to Workspace".

image

After browsing to the Camera folder I clicked Finish and Eclipse imported the project. Et voila. I now had a working Camera app (I can run it in the emulator and on my phone) which I could rip apart at my leisure. In doing so I'd learn how the pros did it.

Standing on the shoulders of giants? Who? Me?

Gotchas

When you install an app from the Android source the code will be in packages with names beginning "com.android.*". You're going to want to change this if the same app/package is already on the phone if you, ultimately, want to ever release the app to the market.

To rename the packages you need to refactor the code. Right-click the packages in the Eclipse and choose "Refactor - Rename", like so:

image

Give the packages your own prefix. In my case I changed com.android.* to com.rockalldesign.*. Eclipse does a good job of changing all references of one to the other, but it leaves a few in place - particularly in the XML files. You'll need to go and address each error one-by-one until it builds ok and you can launch/install it.

There might be a couple of other gotchas and things you need to do to get it to build. I forget now. This isn't for the feint-hearted. Trust me though. I've done this and it works. I have my own prototype app on my phone now, which is based around the stock camera app!

Depending on what your goal is you might want to choose another of the stock apps as you starting point.

Is It Legal?

Is it ok to take Android source and make you own app out of it? I don't know. My understanding of what "open source" means is probably not exactly what it does mean. Anybody?

Comments

  1. What you're doing is not only legal, it is encouraged. Everything in the Android Open Source Project that sits above the Linux kernel is licenced under the Apache 2.0 Software Licence.

    Its exactly what HTC, Sony Ericsson, Samsung and the rest do for their own custom camera apps - build upon and extend (and sometimes ruin) the stock Android implementation.

      • avatar
      • Jake Howlett
      • Fri 12 Aug 2011 05:28 AM

      Phew. I can sleep at night safe in the knowledge Google won't be coming after the millions I'm going to make from my idea. I will make loads of money, right?

      Show the rest of this thread

  2. I installed the Egit plugin in Android SDK (on Windows). Now I can check out the code like I am used to using CVS or SVN.

    If only the emulator could get through the firewall...

      • avatar
      • Jake Howlett
      • Fri 12 Aug 2011 07:43 AM

      Thanks Mark. Installed and using egit now. Brilliant.

    • avatar
    • Patrick L
    • Sat 19 Nov 2011 08:23 PM

    It seems that the Android source code has moved - the command you need to get the camera app is now this:

    git clone https://android.googlesource.com/platform/packages/apps/Camera.git

    This will get the latest version of the Android source code. If you want a previous version you need to get a different branch of the source code, eg. for the Android 2.2 (froyo) version do this:

    git clone https://android.googlesource.com/platform/packages/apps/Camera.git camera -b froyo

    this page has the names of the branches

    http://source.android.com/compatibility/downloads.html

    • avatar
    • Mike Butcher
    • Fri 30 Mar 2012 12:55 PM

    I have been researching Android and Domino using a framework called PhoneGap. Check out my article: http://bit.ly/Ht2xJM

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Fri 12 Aug 2011

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content