O'Reilly logo

Android Studio Cookbook by Mike van Drongelen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Capturing images the easy way

There are of course, many ways on Android to take a picture or record a video. The easiest way to capture an image is by using an intent to launch the camera app and grabbing the results once the image has been taken.

Getting ready

For this recipe, you just need to have Android Studio up and running.

How to do it...

Launching a camera intent typically goes like this:

  1. In Android Studio, create a new project.
  2. In the activity_main.xml layout, add a new button and an image view. Name the image view image.
  3. Create an on-click handler for that button.
  4. Call the takePicture method from the event handler implementation.
  5. Implement the takePicture method. If supported by the device, launch the capture intent:
    static final int REQUEST_IMAGE_CAPTURE ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required