Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android Studio Cookbook

You're reading from  Android Studio Cookbook

Product type Book
Published in Oct 2015
Publisher
ISBN-13 9781785286186
Pages 232 pages
Edition 1st Edition
Languages
Author (1):
Mike van Drongelen Mike van Drongelen
Profile icon Mike van Drongelen
Toc

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 $15.99/month. Cancel anytime}