More Android Development – Taking a Picture From Your App

Ok folks – many Bothans died to bring you this information (along with a good number of my brain cells and sanity points) so I hope you appreciate it.

Let’s say that you’re developing an app and you want to let your users take a picture from inside of the application. Maybe you’re writing an app that will let you take a picture of your friend and then superimpose a rainbow halo over their head. Or maybe you’re writing an app to let people track their comic book collection by cover art. Or maybe you just wanna let people post pictures of food. Whatever, I dunno.

If you google for something obvious like “Android development camera” you’ll hit a bunch of links like this one that will describe a process so arcane that you’ll end up waving a dead chicken over your device while intoning verses from an ancient book written in a dead language just to get it to work properly.

I tried those solutions and ran into a serious problem – right now, Android devices are slowly but surely being upgraded to the 2.1 api, but most phones are still running 1.6. The issue here is that the camera api has changed quite a bit between 1.6 and 2.1. Unless you want to fork your code and release 2 different versions (hint: you don’t) you need to code to the lowest common denominator, API-wise.

After a weekend of threatening, cajoling and finally pleading with the API to just TAKE A DAMNED PICTURE, I came across a solution. Feel free to use this code in your own projects. If you DO use it, I’d love a shoutout or at least an email saying thanks.

  1. ZOMG!!! Your code was hilarious and helpful. Thanks!

    • Matt
    • July 1st, 2011

    You, sir, are a life saver. You just saved a lot of my time and sanity.

    Cheers

  2. @Matt

    Glad I could help! I really need to get better about recording solutions to those small issues that aren’t very well documented.

  3. @Phil Monroe

    Glad you liked it!

    • Cristian
    • November 12th, 2011

    thank you! nice solution

  1. No trackbacks yet.


Warning: gzinflate(): data error in /home/mdinstuhl/dinstuhl.org/wp-includes/http.php on line 1787