From 5dc3f524c7df5444f869b951657666294d4182ef Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Wed, 8 Jul 2026 17:31:50 +0200 Subject: [PATCH 1/2] MediaPicker (.NET 11): document Android result recovery Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../device-media/picker.md | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/docs/platform-integration/device-media/picker.md b/docs/platform-integration/device-media/picker.md index b205981f87..963a3e74a2 100644 --- a/docs/platform-integration/device-media/picker.md +++ b/docs/platform-integration/device-media/picker.md @@ -1,7 +1,7 @@ --- title: "Media picker for photos and videos" description: "Learn how to use the IMediaPicker interface in the Microsoft.Maui.Media namespace, to prompt the user to select or take a photo or video" -ms.date: 12/16/2024 +ms.date: 07/08/2026 no-loc: ["Microsoft.Maui", "Microsoft.Maui.Media", "MediaPicker"] --- @@ -188,7 +188,47 @@ foreach (var file in results) ::: moniker-end > [!IMPORTANT] -> All methods must be called on the UI thread because permission checks and requests are automatically handled by .NET MAUI. +> Media picker methods that open the camera or picker UI must be called on the UI thread because permission checks and requests are automatically handled by .NET MAUI. + +::: moniker range=">=net-maui-11.0" + +### Recover interrupted Android media picker operations + +On Android, the system can destroy and recreate your app while the camera or photo picker UI is in front. If the original media picker task is gone when your app resumes, use the Android-only recovery APIs to retrieve any accepted results. + +Recovery is available for AndroidX-backed media picker operations: capture photo, capture video, pick a photo, pick photos, pick a video, and pick videos. Each has an , a , and a collection containing recovered objects. The value identifies the operation as `CapturePhoto`, `CaptureVideo`, `PickPhoto`, `PickPhotos`, `PickVideo`, or `PickVideos`. + +```csharp +using System.IO; +using Microsoft.Maui.Media; +using Microsoft.Maui.Storage; + +async Task RecoverMediaPickerResultsAsync() +{ + var results = await MediaPicker.GetRecoveredMediaPickerResultsAsync(); + + foreach (var result in results) + { + foreach (var file in result.Files) + { + var destination = Path.Combine(FileSystem.CacheDirectory, file.FileName); + + using var source = await file.OpenReadAsync(); + using var target = File.Create(destination); + await source.CopyToAsync(target); + } + + await MediaPicker.ClearRecoveredMediaPickerResultAsync(result.Id); + } +} +``` + +Use to query already recovered results, and call after your app handles each result. If your startup or resume flow needs to wait for recovery reconciliation, call with a . If the app should abandon a pending media picker operation instead, call . + +> [!IMPORTANT] +> Media picker result recovery is Android-only and doesn't change media picker behavior on iOS, Mac Catalyst, or Windows. + +::: moniker-end ## Take a photo From 145f1190b6136f9618d4def12a4ce322c85e4b67 Mon Sep 17 00:00:00 2001 From: Gerald Versluis Date: Wed, 8 Jul 2026 17:57:49 +0200 Subject: [PATCH 2/2] MediaPicker docs: guard Android recovery sample Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/platform-integration/device-media/picker.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/platform-integration/device-media/picker.md b/docs/platform-integration/device-media/picker.md index 963a3e74a2..5ab4b00a82 100644 --- a/docs/platform-integration/device-media/picker.md +++ b/docs/platform-integration/device-media/picker.md @@ -196,13 +196,16 @@ foreach (var file in results) On Android, the system can destroy and recreate your app while the camera or photo picker UI is in front. If the original media picker task is gone when your app resumes, use the Android-only recovery APIs to retrieve any accepted results. -Recovery is available for AndroidX-backed media picker operations: capture photo, capture video, pick a photo, pick photos, pick a video, and pick videos. Each has an , a , and a collection containing recovered objects. The value identifies the operation as `CapturePhoto`, `CaptureVideo`, `PickPhoto`, `PickPhotos`, `PickVideo`, or `PickVideos`. +Recovery is available for AndroidX-backed media picker operations: capture photo, capture video, pick a photo, pick photos, pick a video, and pick videos. Each `RecoveredMediaPickerResult` has an `Id`, a `Kind`, and a `Files` collection containing recovered objects. The `RecoveredMediaPickerResultKind` value identifies the operation as `CapturePhoto`, `CaptureVideo`, `PickPhoto`, `PickPhotos`, `PickVideo`, or `PickVideos`. + +Because the recovery APIs are Android-only, place recovery code in an Android-specific file or guard it with `#if ANDROID` in shared code. ```csharp using System.IO; using Microsoft.Maui.Media; using Microsoft.Maui.Storage; +#if ANDROID async Task RecoverMediaPickerResultsAsync() { var results = await MediaPicker.GetRecoveredMediaPickerResultsAsync(); @@ -221,9 +224,10 @@ async Task RecoverMediaPickerResultsAsync() await MediaPicker.ClearRecoveredMediaPickerResultAsync(result.Id); } } +#endif ``` -Use to query already recovered results, and call after your app handles each result. If your startup or resume flow needs to wait for recovery reconciliation, call with a . If the app should abandon a pending media picker operation instead, call . +Use `MediaPicker.GetRecoveredMediaPickerResultsAsync` to query already recovered results, and call `MediaPicker.ClearRecoveredMediaPickerResultAsync` after your app handles each result. If your startup or resume flow needs to wait for recovery reconciliation, call `MediaPicker.WaitForRecoveredMediaPickerResultsAsync` with a . If the app should abandon a pending media picker operation instead, call `MediaPicker.DiscardPendingMediaPickerOperationAsync`. > [!IMPORTANT] > Media picker result recovery is Android-only and doesn't change media picker behavior on iOS, Mac Catalyst, or Windows.