Toggle Between the Front- and Back-Facing Cameras

Most mobile Android devices come with both the front-facing and back-facing cameras. We need a UI button that toggles between the front and back camera. Let’s also activate the flash that’s built into most back-facing cameras and add an additional pair of button controls to start and stop the camera. The final app then looks like the following:

images/Camera/FrontBack.png

Android lists all built-in device cameras and allows us to pick the one we’d like to work with. For instance, the Nexus 6 uses the camera index ID 0 for the back-facing camera and 1 for the front-facing camera. Future Android devices might add more cameras ...

Get Rapid Android Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.