# Maui Media Picker

> >-

- **Type:** Skill
- **Install:** `agentstack add skill-davidortinau-maui-skills-maui-media-picker`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [davidortinau](https://agentstack.voostack.com/s/davidortinau)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [davidortinau](https://github.com/davidortinau)
- **Source:** https://github.com/davidortinau/maui-skills/tree/main/plugins/maui-skills/skills/maui-media-picker

## Install

```sh
agentstack add skill-davidortinau-maui-skills-maui-media-picker
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# .NET MAUI Media Picker — Gotchas & Best Practices

## Common Mistakes

### 1. Forgetting to check for cancellation

Single-select returns `null`, multi-select returns an empty list. Not checking causes `NullReferenceException`.

```csharp
// ❌ Crashes when user cancels
var photo = await MediaPicker.Default.PickPhotoAsync();
using var stream = await photo.OpenReadAsync();

// ✅ Always check for null / empty
var photo = await MediaPicker.Default.PickPhotoAsync();
if (photo is null) return;
using var stream = await photo.OpenReadAsync();
```

### 2. Calling from a background thread

All `MediaPicker` methods **must** run on the UI thread or they throw.

```csharp
// ❌ Will throw on some platforms
await Task.Run(async () => await MediaPicker.Default.PickPhotoAsync());

// ✅ Call directly from a command or event handler on the UI thread
var photo = await MediaPicker.Default.PickPhotoAsync();
```

### 3. Not checking IsCaptureSupported

Devices without cameras (emulators, some tablets) will throw if you call capture methods.

```csharp
// ❌ Crashes on devices without a camera
var photo = await MediaPicker.Default.CapturePhotoAsync();

// ✅ Guard with capability check
if (MediaPicker.Default.IsCaptureSupported)
{
    var photo = await MediaPicker.Default.CapturePhotoAsync();
}
```

### 4. Not disposing streams

`OpenReadAsync()` returns a stream that must be disposed.

```csharp
// ❌ Leaks the stream
var stream = await photo.OpenReadAsync();
var bytes = ReadAllBytes(stream);

// ✅ Dispose with using
using var stream = await photo.OpenReadAsync();
```

## Platform Pitfalls

### ⚠️ SelectionLimit is not enforced on Android/Windows

`MediaPickerOptions.SelectionLimit` is advisory. Always validate the count yourself:

```csharp
var options = new MediaPickerOptions { SelectionLimit = 5 };
var results = await MediaPicker.Default.PickPhotosAsync(options);
if (results.Count() > 5)
{
    // Warn user or take only the first 5
    results = results.Take(5);
}
```

### ⚠️ Android storage permissions split at API 33

- API ≤ 32: needs `READ_EXTERNAL_STORAGE` / `WRITE_EXTERNAL_STORAGE`
- API ≥ 33: needs `READ_MEDIA_IMAGES` / `READ_MEDIA_VIDEO` (broad storage permissions are ignored)
- Use `android:maxSdkVersion="32"` on the old permissions to avoid Play Store warnings

### ⚠️ iOS requires all four plist keys for full functionality

Missing any one of `NSCameraUsageDescription`, `NSMicrophoneUsageDescription`,
`NSPhotoLibraryUsageDescription`, or `NSPhotoLibraryAddUsageDescription` causes
a runtime crash when that feature is accessed.

### ⚠️ Android requires `` for camera intents

Without the `IMAGE_CAPTURE` query in `AndroidManifest.xml`, `CapturePhotoAsync`
may fail silently on Android 11+ due to package visibility restrictions.

## Decision Framework

| Scenario | Method |
|---|---|
| User picks one photo | `PickPhotoAsync()` |
| User picks multiple (.NET 10+) | `PickPhotosAsync()` with `SelectionLimit` |
| App needs camera capture | Check `IsCaptureSupported` → `CapturePhotoAsync()` |
| Save picked file permanently | Copy stream to `FileSystem.AppDataDirectory` |
| Need photo metadata | Set `PreserveMetaData = true` in `MediaPickerOptions` |

## Checklist

- [ ] All picker calls run on the UI thread
- [ ] Null/empty checks after every pick/capture call
- [ ] `IsCaptureSupported` guard before capture methods
- [ ] Streams disposed with `using`
- [ ] Android manifest has both old and new storage permissions with `maxSdkVersion`
- [ ] Android manifest has `` block for camera intent
- [ ] iOS `Info.plist` has all four usage description keys
- [ ] `SelectionLimit` validated in code, not trusted from platform

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [davidortinau](https://github.com/davidortinau)
- **Source:** [davidortinau/maui-skills](https://github.com/davidortinau/maui-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-davidortinau-maui-skills-maui-media-picker
- Seller: https://agentstack.voostack.com/s/davidortinau
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
