{
  "id": "android/securityexception-camera-permission-denied",
  "signature": "SecurityException: Camera permission denied. The user has denied the camera permission, or the permission is not declared in the manifest.",
  "signature_zh": "SecurityException: 相机权限被拒绝。用户拒绝了相机权限，或清单中未声明该权限。",
  "regex": "SecurityException: Camera permission denied.*",
  "domain": "android",
  "category": "auth_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "应用尝试访问相机，但未在运行时授予所需的 android.permission.CAMERA 权限，或者 AndroidManifest.xml 中缺少该权限声明。",
  "versions": [
    {
      "version": "Android 12 (API 31)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 13 (API 33)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Android 14 (API 34)",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CameraX 1.3.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using ContextCompat.checkSelfPermission() incorrectly (e.g., checking against a wrong package name) may return GRANTED even when permission is denied.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Requesting the permission in a background thread without UI callback leads to the request being ignored by the system.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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); }",
      "success_rate": 0.95,
      "how": "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); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the AndroidX Activity Result API for a cleaner permission request: registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { openCamera(); } }).launch(Manifest.permission.CAMERA);",
      "success_rate": 0.9,
      "how": "Use the AndroidX Activity Result API for a cleaner permission request: registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { openCamera(); } }).launch(Manifest.permission.CAMERA);",
      "condition": "",
      "sources": []
    },
    {
      "action": "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);",
      "success_rate": 0.85,
      "how": "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);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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); }",
    "Use the AndroidX Activity Result API for a cleaner permission request: registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) { openCamera(); } }).launch(Manifest.permission.CAMERA);",
    "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);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://developer.android.com/training/permissions/requesting",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-03-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}