Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActivityResultContracts.TakePicture() Permission Denied

I'm using the latest Android Activity Result API for taking pictures with the device camera:

    private val takePictureActivityResult =
        registerForActivityResult(ActivityResultContracts.TakePicture()) { isSuccess ->
            if (isSuccess) {
                if (imageUri != Uri.EMPTY) {
                    // SAVE image to external storage
                    currentImagePath = ImageUtils.saveImageToExternalStorage(this,imageUri)
                    addImageView.setImageURI(imageUri)
                }
            }
        }

This results in a SecurityException:

java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.activity.CaptureActivity clip={text/uri-list {...}} (has extras) } from ProcessRecord{81d69c 11563:com.myapp/u0a242} (pid=11563, uid=10242) with revoked permission android.permission.CAMERA

According to Google's documentation:

If your app targets M and above and declares as using the Manifest.permission.CAMERA permission which is not granted, then attempting to use this action will result in a SecurityException.

I'm not using android.permission.CAMERA in the manifest, nor does the app explicitly request camera permissions from the user. I don't understand how a permission could have been revoked if the app never requested it. I do save images to device storage, so those permissions are in the manifest.

Thanks in advance to anyone who can explain this issue.

like image 891
jilbot Avatar asked Dec 18 '25 23:12

jilbot


1 Answers

Double check you do not have the CAMERA permission in you APK.

  1. Go to your app module's AndroidManifest.xml file.
  2. Click the Merged Manifest button below the code area.
like image 142
John 6 Avatar answered Dec 20 '25 17:12

John 6



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!