An empty photo creates if back button was pressed

Viewed 42

The problem is: when camera intent starts, I click back button to close it, then check the gallery and it appears that there is an "empty" photo which was created during this intent. I don't know how to delete it. I've already tried to get path from imageUri variable but when I called File(imageUri.toString()).delete() or File(imageUri.path).delete() in onActivityResult with resultCode = RESULT_CANCELLED it did nothing.

Here's the code of camera intent:

    private var imageUri : Uri? = null

    private fun makeCameraIntent() {
        val values = ContentValues(1)
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg")
        imageUri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values)
        val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        if (intent.resolveActivity(packageManager) != null) {
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            startActivityForResult(intent, cameraActivityRequestCode)
        }
    }

"empty" photos

0 Answers
Related