Camera Permission

Requesting the Camera Permission

CAMERA is a runtime permission. Declare it, and mark the hardware optional so Google Play 1 still offers the app to devices without a camera:

AndroidManifest.xml: the camera permission, hardware optionalXML
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" android:required="false" />

The camera screen asks as it opens, since its purpose is obvious, and explains itself if refused:

camera/CameraScreen.kt: ask first, show the viewfinder only when granted (excerpt)Kotlin
  val ask = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {
    granted = it
  }
  LaunchedEffect(Unit) { if (!granted) ask.launch(Manifest.permission.CAMERA) }
  if (!granted) {
    Text("BookNest needs the camera to photograph a book you want to sell.", modifier)
    return
  }

The dialog (figure in Capturing Photos) also offers a one-time grant that lapses soon after the app leaves the foreground, so check on every visit. For a single photo without the permission, launch the system camera with ActivityResultContracts.TakePicture().