Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Using a Camera Intent
The basic process to take a photo is relatively straightforward: You launch an external camera app, the user takes a photo, and then you update the crime with the path to the new file. To implement this, you are once again going to rely on the Activity Results API.
This time you are going to use the ActivityResultContracts.TakePicture() contract. It takes in a Uri, which will be generated by the FileProvider class using a File you will create. Once the user is finished taking the photo, the contract does not return that same Uri. Instead, it returns a Boolean telling you whether an image was saved to the file.
Create a class property on CrimeDetailFragment named takePhoto and initialize it using the Activity ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access