Skip to content

Update camera and photo picker for Android 13+ and iOS 14+ API changes #5

@jimmckeeth

Description

@jimmckeeth

Overview

TTakePhotoFromCameraAction and TTakePhotoFromLibraryAction still function in Delphi's FMX layer, but the underlying platform APIs they rely on have changed significantly. Several behaviors that worked in 2018 are broken or deprecated on Android 13+ and iOS 14+.

Background

Android Changes

  • Android 11+ (API 30): Camera intents must use a FileProvider URI, not a bare file:// URI. Delphi 13's FMX runtime handles this internally, but any custom camera code using direct paths will throw FileUriExposedException.
  • Android 13 (API 33): The new Photo Picker (ACTION_PICK_IMAGES) is the recommended replacement for ACTION_OPEN_DOCUMENT and gallery intents. It does not require any READ_MEDIA_IMAGES permission.
  • Camera permission: Still required for TTakePhotoFromCameraAction.

iOS Changes

  • iOS 14: PHPickerViewController replaced the old UIImagePickerController for photo library access. Delphi's FMX TTakePhotoFromLibraryAction wraps the native picker — verify that Delphi 13's implementation uses PHPickerViewController.
  • iOS 14 Limited Photo Library Access: Users can grant access to selected photos only rather than the full library. Apps must handle the .limited authorization status gracefully.
  • iOS 16+: UIImagePickerController for camera is deprecated (but still works); AVFoundation is now preferred for custom camera UIs.

Current Code Pattern

In uNewEntryFrame.pas, the code calls TTakePhotoFromCameraAction and TTakePhotoFromLibraryAction actions and handles the OnDidFinishTaking event. The TBitmap result is scaled to max 1024×512 and stored. This flow needs verification against Delphi 13's updated FMX media library actions.

Files Affected

lab-src/Lab05.../frames/uNewEntryFrame.pas
lab-src/Lab06.../frames/uNewEntryFrame.pas
... (Lab05 through Lab12)
lab-src/Lab*/forms/formMain.pas  (action wiring)

Steps to Address

  1. Verify that Delphi 13's TTakePhotoFromCameraAction correctly uses a FileProvider URI on Android — test on API 30+ emulator.
  2. Verify that TTakePhotoFromLibraryAction uses PHPickerViewController on iOS 14+ — check Delphi 13 release notes or FMX source.
  3. Add handling for iOS limited photo library authorization status: if the user grants limited access, inform them rather than silently failing.
  4. Test image resize logic (max 1024×512) still functions correctly with the bitmap returned by the updated actions.
  5. Ensure the android.permission.CAMERA runtime request uses System.Permissions.RequestPermissions (not raw JNI) consistently.
  6. Update lab instructions to explain the Photo Picker flow for Android 13+ and limited library access on iOS 14+.

Test Plan

  • On Android 13 emulator: tapping "Take Photo" opens the native camera; the captured image appears in the entry detail view.
  • On Android 13 emulator: tapping "Choose from Library" opens the Android Photo Picker (no permission dialog — Photo Picker is permission-free).
  • On Android 11 emulator: no FileUriExposedException is thrown when capturing a photo.
  • On iOS 17 device/simulator: tapping "Take Photo" opens the camera; result is displayed correctly.
  • On iOS 17 device/simulator: tapping "Choose from Library" opens PHPickerViewController.
  • Selecting "Limited Access" in the iOS photo permission prompt does not crash the app.
  • Captured/selected images are stored in the database and reload correctly after app restart.
  • Images are correctly scaled to ≤ 1024×512 pixels before storage.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions