0

I have a onActivityResult that handles a case CAMERA_PHOTO_REQUEST and it works until I add a ".putExtra" argument to the Intent.

Works:

val cameraPhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(cameraPhotoIntent, PermissionHandler.REQUEST_TAKE_PHOTO)

Doesn't work:

val cameraPhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
cameraPhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI)
startActivityForResult(cameraPhotoIntent, PermissionHandler.REQUEST_TAKE_PHOTO)

onActivityResult:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    when (requestCode) {
        PermissionHandler.REQUEST_TAKE_PHOTO ->
            if (resultCode == RESULT_OK && data != null) { //result code becomes -1 and data = null after I change to the new semantics
                val extras = data.extras
                val imageBitmap = extras.get("data") as Bitmap
                profile_image.setImageBitmap(imageBitmap)
                galleryAddPic()
            }
    }
}

My plan is to change the galleryAddPic() with the .putExtra() argument since APIs over 22 needs the later. When I add the .putExtra, the image is indeed saved to the phone, but since it gives me a -1 result code it won't trigger the onActivityResult block and thus the profile picture won't be set.

EDIT: onActivityResult catches the intent with the right request code, but the result code is -1 and the data is null. It is as if the Result catcher catches the .putExtra part gets caught instead of the actual intent...

Ty for taking time to help a late friday like this.

Joel Broström
  • 3,530
  • 1
  • 34
  • 61

0 Answers0