Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Studio Cookbook

You're reading from   Android Studio Cookbook Design, test, and debug your apps using Android Studio

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781785286186
Length 232 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mike van Drongelen Mike van Drongelen
Author Profile Icon Mike van Drongelen
Mike van Drongelen
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

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 = 1;
    private void takePicture() {
      Intent captureIntent = new  
        Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      if (captureIntent.resolveActivity(  
       getPackageManager()) != null) {
        startActivityForResult(captureIntent,   
          ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime