I want to get the data in putExtra() but it returns null in it.data
. I refered to other solutions but they are either quite old or they are in Java.
I've check photoURI in Log.d and it does have a string in it, meaning the photoURI is not null.
lateinit var photoURI: Uri
photoFile?.also {
Log.d(TAG, "Success creating file")
photoURI = FileProvider.getUriForFile(
requireContext(),
"com.example.mobilee_commerceapp",
it
)
}
Log.d(TAG, "URI IS: " + photoURI.toString())
val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoURI)
getCameraResult.launch(takePictureIntent)
it.data in getCameraResult = registerForActivityResult()
shown below keeps returning null, printing the message "getCameraResult: error occured" in Logcat.
private val getCameraResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if(it.resultCode == Activity.RESULT_OK && it.data != null) {
Log.d(TAG, "URI has :" + it.data!!.hasExtra("photoUri"))
} else {
Log.e(TAG, "getCameraResult: error occured")
I tried putting it into a Bundle, but it.data = null
I also tried using just .putExtra
, and it.data still = null