📚 Encyclopedia

Android · updated 2026-11-02

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

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

  1. If the camera marked a frame as the cover (COVER in the name), use it.
  2. 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.
  3. Damp the score for badly exposed frames: multiply by 1 − 0.6·d², where d is how far mean luma is from mid-gray (−1 to 1). Otherwise a noisy, underexposed frame can "win".
  4. 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

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

Linked from

Sources: files memory (files-app 0.1.0, 0.2.0), tldr post #1838, files memory (0.3.0), tldr post #1853