简体   繁体   English

Android ActivityResultContracts.TakePicture() 权限被拒绝

[英]Android ActivityResultContracts.TakePicture() Permission Denied

I'm using the latest Android Activity Result API for taking pictures with the device camera:我正在使用最新的 Android 活动结果 API 使用设备相机拍照:

    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:这会导致 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.我没有在清单中使用android.permission.CAMERA ,应用程序也没有明确向用户请求相机权限。 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.仔细检查您的 APK 中没有 CAMERA 权限。

  1. Go to your app module's AndroidManifest.xml file. Go 到您的app模块的 AndroidManifest.xml 文件。
  2. Click the Merged Manifest button below the code area.单击代码区域下方的Merged Manifest按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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