Using a Camera Intent
The next step is to actually take the picture. This is the easy part: You get to use an implicit intent again.
Start by stashing the location of the photo file. You will use it a few more times, so this will save a bit of work.
Listing 16.10 Grabbing the photo file location (CrimeFragment.kt
)
class CrimeFragment : Fragment(), DatePickerFragment.Callbacks { private lateinit var crime: Crime private lateinit var photoFile: File ... override fun onViewCreated(view: View, savedInstanceState: Bundle?) { ... crimeDetailViewModel.crimeLiveData.observe( viewLifecycleOwner, Observer { crime -> crime?.let { this.crime = crime photoFile = crimeDetailViewModel.getPhotoFile(crime) updateUI() } }) } ... }
Get Android Programming: The Big Nerd Ranch Guide, 4th Edition 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.