I have two separate problems with the call
requireActivity().revokeUriPermission(photoUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
The first is when the call is only in onActivityResult()
. This is throwing the same error as described in Problem with LiveData upon return from camera except this time photoUri
is not initialized. It is the exact same reasoning as the other thread - the database call has not been resolved yet.
The second is when the call in onDetach()
. This time the error is
java.lang.SecurityException: Permission Denial: writing
androidx.core.content.FileProvider uri
content://criminalintentbnr4k.fileprovider/crime_photos/
IMG_461f153a-34b8-43fe-aaf4-9696fae09dd7.jpg from pid=23835,
uid=10059 requires the provider be exported, or grantUriPermission()
This is too be expected from the onDetach()
method. The life cycle flow when the camera button is pressed is:
- photoButton.onClickListener()
- requireActivity().grantUriPermission()
- startActivityForResult()
- CrimeFragment::onPause()
- MainActivity::onDestroy()
- CrimeFragment::onDestroyView()
- CrimeFragment::onDestroy()
- CrimeFragment::onDetach()
- requireActivity().revokeUriPermission()
- CrimeListFragment::onDestroy()
- CrimeListFragment::onDetach()
so when the the camera activity is completed, it already has had the Write permission revoked.
I don’t know how to solve either of these issues because the fragment is being completely destroyed so any life cycle method will fire.