Theory

The camera, permissions and QR

In lesson 9 orders already worked, but tableNumber was null — the server didn't know which table you were at. Pica's idea: every table has a QR sticker (e.g. table:12). You scan it, and the pizza arrives at exactly your table.

For that we need three things:

  • The camera permission. The camera is a "dangerous" permission on Android. Declaring it in the manifest isn't enough; since Android 6 (API 23) you must request it at runtime, via a dialog, and only show the preview once it's granted.
  • A CameraX preview. CameraX is the modern Jetpack camera API. LifecycleCameraController + PreviewView show the feed; we embed it in Compose via AndroidView (because PreviewView is a legacy View, not a composable).
  • QR reading. The ML Kit barcode scanner analyzes frames and returns the code it finds. MlKitAnalyzer is attached to the camera as an analyzer.

The flow:

Camera (CameraX) ──frames──▶ ML Kit analyzer ──"table:12"──▶ TableSession ──▶ order

We keep the scanned table in a TableSession class (one Koin single), so the cart, the checkout and the order all see the same table.

Verify-docs. CameraX (1.6.x) + camera-mlkit-vision + ML Kit barcode (17.3.0) — the surface of these APIs (especially MlKitAnalyzer and LifecycleCameraController) shifts between versions. At authoring time, check the current sample in the Android docs.