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?

      Hide the rest of this thread

        • avatar
        • CJ
        • Fri 12 Aug 2011 07:53 AM

        They'll come after you for millions because you've unwittingly infringed on one of their software patents!

          • avatar
          • Jake Howlett
          • Fri 12 Aug 2011 08:15 AM

          We're talking about Google here, not Apple ;-)

          Yeah, I know, I know, they're all at it. Can't helping thinking Apple is coming out the bad guy at the moment though in the "everybody suing everybody else" game they're playing

            • avatar
            • CJ
            • Fri 12 Aug 2011 08:39 AM

            Heh, I'm sure there must be good things about software patents, but all I ever hear about is "X sueing Y for infringment".

            I was never really in favour of the software patent idea (although that could easily be through ignorance), and everything I've heard since has just made me roll my eyes.

              • avatar
              • Patrick L
              • Fri 12 Aug 2011 10:20 AM

              One of the things that isn't made clear in the reporting on software patents is that they are pretty much only available in the US, so if Google did loose to Apple over Android or whatever, in theory it wouldn't affect Google's ability to market Android outside the US.

              Maybe Google should bring it all to a head by saying the rest of the world can have a set of features, but the US users won't get them because of the threat of software patents held by other companies.

                • avatar
                • Jake Howlett
                • Tue 16 Aug 2011 04:39 AM

                But Samsung have recently been banned from selling the Galaxy Tab 10.1 in Europe! Because of, apparently, some ruling in a German court.

                http://tech.fortune.cnn.com/2011/08/09/major-android-setback-galaxy-tab-banned-in-europe/

                Although, last I read, I think they might be looking in to it again.

        • avatar
        • IanB
        • Sat 13 Aug 2011 02:31 AM

        Don't you have to publish your code, if it's built on FOSS so that others can use your app and rip it apart and build on it too?

        1. No. You only have to publish the code if you deliver the app to someone. That is if you make the app available for a fee or free. So if you use it internally in a company then there's no requirement to publish.

            • avatar
            • Jake Howlett
            • Tue 16 Aug 2011 03:54 AM

            Hmm, interesting. I don't like the sound of that.

            So, the camera app on my Galaxy S2, which I assume Samsung built using the stock camera app as the starting point is available somewhere for download too?

            I might look in to this some more...I'll report back what I find if I do.

              • avatar
              • Jake Howlett
              • Tue 16 Aug 2011 06:10 AM

              Sure enough, it seems you can get the source of Samsung's S2 build here:

              https://opensource.samsung.com/rece.. ..ption_main.do?method=reception_search&searchValue=I9100

              Whether than proves the above assertion that you *have* to do so or not I don't know...

                • avatar
                • Tom
                • Tue 16 Aug 2011 06:50 AM

                I think the apache license is somewhere in between the GPL and BSD. See here http://www.apache.org/licenses/LICENSE-2.0

                From a quick skim, it sounds to me you don't have to distribute the source of your modified version, but there are copyright notices you have to adhere to.

                Obviously IANAL, so check this for yourself before acting on it.

  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