A Photo Picker for Android and iOS Without Asking for Permission
By Nesim Razon, independent mobile developer · 2026-11-18
Our greeting card feature lets the player put their own photo on a card. We wanted it to work on Android and iPhone, to ask for no permission, and to keep the picture on the device. The system photo pickers make that possible. The interesting part is the small shared contract that hides the two very different implementations.
The shared contract
Common code sees one function: pick an image, then call back with the bytes of a picture, or with nothing if the player cancelled or something failed. The default implementation simply returns nothing, so a platform that has no picker is not a problem. Next to it sits one expected function that turns bytes into a bitmap Compose can draw, with a separate real implementation on each platform.
The promise of the contract matters more than its type. Whatever the platform does inside, the bytes that arrive are a JPEG whose longest side is at most 1600 pixels. Common code never has to care about camera resolutions, rotation flags or memory.
Android: the system picker and careful decoding
On Android we use the system photo picker through the activity result contract for picking visual media, images only. It needs no storage permission, because the player hands over exactly one picture. The result arrives as a content address, and reading it happens on a background thread so the screen never stutters.
Reading a twelve megapixel photo naively can run a small phone out of memory. So the code first reads only the image bounds, then picks a power-of-two sample size until the longest side is no more than 3200 pixels, decodes that, applies the EXIF orientation as a rotation of 90, 180 or 270 degrees, scales to at most 1600 pixels and writes a JPEG at quality 90. The rotation step is the one people forget: without it, portrait photos from some cameras arrive sideways.
iOS: PHPicker and a base64 string
On iPhone the equivalent is the photo picker view controller, configured for images and a selection limit of one. It also needs no permission and shows the player's library in a sheet. In the delegate we load the picture as an image, scale it to at most 1600 pixels by drawing it into a new renderer, which also bakes in its orientation, and encode it as a JPEG at quality 0.9.
The bytes then cross from Swift to Kotlin as a base64 string, and Kotlin decodes them. That looks wasteful, but it keeps the bridge to the simplest possible type, a string, instead of fiddling with raw memory objects across the language boundary. At this image size the cost is invisible.
Decoding for display
Once common code has the bytes it asks for a bitmap. On Android the real function uses the platform bitmap decoder. On iPhone it uses the Skia image from the Compose runtime: make an image from the encoded bytes and convert it to a Compose bitmap. Both are wrapped so that a corrupt file returns nothing instead of throwing.
Privacy by construction
The picture never leaves the device in this feature. It is picked locally, resized locally and drawn onto a card that the player then shares through the normal system share sheet. Because no photo permission is requested and nothing is uploaded, the store privacy forms stay short, which is a feature of its own.
What to take away
- Use the system pickers: no permission, less code, a better first run.
- Resize on the platform side to a fixed maximum, so common code deals with one known shape.
- Read orientation data before you scale, or portrait photos will turn up sideways.
- Prefer the simplest type across the Swift bridge, even if it looks wasteful.
- Return nothing on any failure and let the caller decide, instead of throwing across layers.
Frequently asked questions
Does the photo picker need a permission?
No. Both the Android system photo picker and the iPhone PHPicker run outside the app and hand over only the picture the player chooses.
Why resize to 1600 pixels?
It is large enough to look sharp on a card and small enough to keep memory use low and to share quickly.
Why do some photos arrive sideways?
Many cameras store the rotation in a metadata flag instead of rotating the pixels, so you must read the EXIF orientation and apply it.
Why pass the picture as base64 from Swift?
It keeps the bridge to a plain string, which avoids awkward conversions of raw memory between Swift and Kotlin.
More from the blog
Cloud Save on Android and iOS: The Merge Rule That Never Loses Progress
How an Advent Calendar App Decides Which Door Opens Today
How to Run an Online Secret Santa Draw (Free, No Sign-Up)
Open Source Astronomy on Android and iOS With One Patch Script- Cloud iOS Signing: A New Certificate on Every Build, and the Fix
- The iOS Build Number That Stayed at 1: Three Failed Fixes and One That Worked