An Android file manager, photo bursts, and cropping
androidstoragemanage-external-storagefile-managerphotosburstimage-sharpnesslaplaciancropexif
A general file manager on modern Android needs one special permission, and once it can see every photo it runs into a very practical annoyance: camera bursts flood the grid with near-identical frames. Justin's Files app (io.jhampton.files, Kotlin + Compose, minSdk 29, shipped 2026-10-23) handles both. This article covers the storage access model and the burst detection and best-frame scoring, which are reusable in any gallery.
Storage access
- Since Android 11, scoped storage limits ordinary apps to their own files, MediaStore media, and documents the user picks through the Storage Access Framework. A real file manager needs
MANAGE_EXTERNAL_STORAGE("All files access"). It is not a runtime dialog: checkEnvironment.isExternalStorageManager()and send the user toSettings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION(withpackage:data). A card on the home screen that asks for it is enough. - Google Play restricts this permission to file managers and similar apps; for sideloaded and F-Droid apps it is just a settings toggle.
- With it, plain
java.io.Fileworks across shared storage, which keeps copy, move, rename, zip extraction and search simple. Category views (Images, Videos, Documents, APKs) can come from extension-based kind detection. - Volumes:
StorageManager.storageVolumeslists internal storage and any SD card or USB drive, withStatFsfor usage bars. Removable volumes still need real-hardware testing.
Detecting photo series
Use the timestamp in the file name, never the modification time. Copying a folder of photos gives every file the same mtime, which would make the whole folder look like one burst. Camera apps write the capture time into the name:
- ZTE: IMG_331_BURST20261024034020.jpg; Pixel: 00001IMG_00001_BURST20190101120000.jpg; Samsung rapid shots: 20261024_034020_001.jpg.
- One regex finds yyyyMMdd[_-]HHmmss[mmm] anywhere in the name; validate month, day and time ranges so random digit runs do not match.
- Rules that worked: frames marked BURST in the same folder chain together when consecutive stamps are at most 2 s apart (2 frames minimum). Other stamped photos need 3 or more within 1 s to count as a series, so two quick snapshots stay separate.
- Within a series, order by stamp, then by frame number.
Picking the best frame
- If the camera marked a frame as the cover (
COVERin the name), use it. - Otherwise score each frame for sharpness: decode at about 480 px on the long side (software bitmap), convert to luma, apply the 4-neighbor Laplacian (
4·p − left − right − up − down) over the central 80% of the image, and take its variance. Blurry frames have weak edges and low variance. Ignoring the border avoids edge artifacts and vignetting. - Damp the score for badly exposed frames: multiply by
1 − 0.6·d², wheredis how far mean luma is from mid-gray (−1 to 1). Otherwise a noisy, underexposed frame can "win". - Cache the winner per series (here in SharedPreferences) so scoring runs once.
A synthetic 15-frame burst with blur applied to all but one frame picked the sharp one on the emulator.
The UI around it
- Show a series as one tile: a stacked-cards cell with a count badge in grids, a row in lists, and in the Recent strip.
- Tapping opens a viewer with a filmstrip, the best frame starred, and "Keep only this frame", which deletes the rest. Selecting a series selects all its frames, so copy and delete stay honest.
- In the normal swipe viewer, a series is one page with a "N photos in this series · View all" pill.
- A setting (and an overflow toggle) shows every photo instead. Search results stay ungrouped, since a search is usually for a specific file.
Crop and rotate (0.3.0)
A crop tool in the image viewer, with lessons that apply to any Android image editor:
- Keep the crop box in fractions (0..1) of the picture as displayed, after quarter turns. Rotating turns the box with the picture. At save time map it back to the original's frame; for one clockwise turn, (u, v) ← (v, 1 − u). Fixed-ratio presets drag by the corners only, and a quarter turn swaps 4:3 for 3:4.
- Corner handles near the screen edge trigger the system back gesture. Mark the crop canvas with Modifier.systemGestureExclusion().
- Decode at full resolution with ImageDecoder and only downscale when the pixel count would exceed a fraction of the heap (about 1/20 here), so a crop is not silently a resize.
- Save a copy by default (name_crop.jpg, then _crop2…). Formats Android cannot encode (HEIC, GIF, BMP) always become a JPEG copy. Overwrite only JPEG, PNG and WebP, after a confirmation, by writing a temp file and renaming it over the original.
- Copy the EXIF (date, camera, exposure, GPS) to the output, but reset the orientation tag to normal: the pixels are already upright, and a stale "rotate 90" tag makes viewers turn it again. Test with a JPEG that carries orientation 6.
- Keep the burst detector from treating a _crop or _edit copy as another frame of the series.
See also
- In-app updates for sideloaded Android apps
- A self-hosted F-Droid repository and APK catalog
- Driving the Android emulator headlessly for QA