# SecurityException: Camera permission denied. The user has denied the camera permission, or the permission is not declared in the manifest.

- **ID:** `android/securityexception-camera-permission-denied`
- **Domain:** android
- **Category:** auth_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

App attempts to access the camera without the required android.permission.CAMERA being granted at runtime, or the permission is missing from AndroidManifest.xml.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 12 (API 31) | active | — | — |
| Android 13 (API 33) | active | — | — |
| Android 14 (API 34) | active | — | — |
| CameraX 1.3.0 | active | — | — |

## Workarounds

1. **Declare <uses-permission android:name="android.permission.CAMERA" /> in AndroidManifest.xml. Then in code, request the permission: if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_CODE); }** (95% success)
   ```
   Declare <uses-permission android:name="android.permission.CAMERA" /> in AndroidManifest.xml. Then in code, request the permission: if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_PERMISSION_CODE); }
   ```
2. **Use the AndroidX Activity Result API for a cleaner permission request: registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { openCamera(); } }).launch(Manifest.permission.CAMERA);** (90% success)
   ```
   Use the AndroidX Activity Result API for a cleaner permission request: registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { openCamera(); } }).launch(Manifest.permission.CAMERA);
   ```
3. **If the user has permanently denied the permission, show a rationale dialog and guide them to Settings: Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null)); startActivity(intent);** (85% success)
   ```
   If the user has permanently denied the permission, show a rationale dialog and guide them to Settings: Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", getPackageName(), null)); startActivity(intent);
   ```

## Dead Ends

- **** — Adding the permission to AndroidManifest.xml without requesting it at runtime on Android 6+ still causes the error because the user hasn't granted it. (90% fail)
- **** — Using ContextCompat.checkSelfPermission() incorrectly (e.g., checking against a wrong package name) may return GRANTED even when permission is denied. (70% fail)
- **** — Requesting the permission in a background thread without UI callback leads to the request being ignored by the system. (80% fail)
