Capturing images using the camera
Android provides two ways to write apps that use a camera:
- One way is to write a camera app from scratch and utilize any or all of the features of any camera that the device may have. This is a big topic and is usually only used when the app is designed to add some kind of a new camera functionality.
- The other way is to use the existing camera app to do the work for us.
We will be cheating (in a good way) by using the existing camera app of the device (option 2). We can do this using the Intent
class that we first saw in Chapter 15, Android Intent and Persistence.
By carefully constructing the argument passed into the constructor of the Intent
class, we can get other apps to do work for us. We will see the code to capture an image, but the same simple techniques can be used to send an e-mail, post a message on social media platforms, play media, and much more besides this.
To have an Intent
class launch the camera app, we will build an Intent
class with android...