【问题标题】:Android ActivityResultContracts.TakePicture() Permission DeniedAndroid ActivityResultContracts.TakePicture() 权限被拒绝
【发布时间】:2022-01-21 20:52:48
【问题描述】:

我正在使用最新的 Android Activity Result 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)
                }
            }
        }

这会导致 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

根据谷歌的文档:

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.

我没有在清单中使用android.permission.CAMERA,该应用也没有明确向用户请求相机权限。我不明白如果应用程序从未请求过权限,如何撤销权限。我确实将图像保存到设备存储中,因此这些权限在清单中。

提前感谢任何可以解释此问题的人。

【问题讨论】:

    标签: android permissions image-capture


    【解决方案1】:

    仔细检查您的 APK 中没有 CAMERA 权限。

    1. 转到 app 模块的 AndroidManifest.xml 文件。
    2. 点击代码区下方的Merged Manifest按钮。

    【讨论】:

      猜你喜欢
      • 2013-07-03
      • 2015-12-21
      • 2020-06-03
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 1970-01-01
      • 2012-06-13
      相关资源
      最近更新 更多