简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM