DEV Community

Ismoy Belizaire
Ismoy Belizaire

Posted on

Smarter Android Picking: ImagePickerKMP Automatically Chooses Gallery or File Explorer

Android media picking has become increasingly complex over the years. Depending on the OS version, the installed apps, and the requested MIME types, the "best" way to pick an image might be the system Photo Picker, a third-party Gallery app, or the system File Explorer. ImagePickerKMP 1.0.35 introduced logic to handle this choice automatically. The documentation at https://imagepickerkmp.dev/ describes this as a unified gallery picker.

The core problem is MIME type support. While most gallery apps are great at showing JPEGs and PNGs, they often fail when asked to show PDFs or specialized file formats. If a developer asks for image/*, a gallery is perfect. If they ask for application/pdf, a file explorer is required.

ImagePickerKMP solves this by inspecting the requested MIME types. If the request is purely for images or videos, it prioritizes the gallery experience. If the request includes non-media types, it seamlessly falls back to the file explorer.

Request Primary UI Fallback
image/* System Gallery / Photo Picker File Explorer
video/* System Gallery / Photo Picker File Explorer
application/pdf File Explorer N/A
Mixed types File Explorer N/A

For the current platform matrix and MIME type support details, visit the official documentation at https://imagepickerkmp.dev/.

val picker = rememberImagePickerKMP(
    config = ImagePickerKMPConfig(
        galleryConfig = GalleryConfig(
            mimeTypes = listOf("image/*", "application/pdf")
        )
    )
)
Enter fullscreen mode Exit fullscreen mode

This "smart picking" means developers don't have to write branching logic to decide which intent to launch. They simply declare what they need, and the library ensures the user sees a valid UI for that selection.

In a world where Android fragmentation remains a challenge, this level of abstraction is a significant time-saver. It ensures that the app remains compatible with older devices while taking advantage of modern system pickers where available.

Check the live documentation at https://imagepickerkmp.dev/ for more information on how to configure MIME types and handle multi-selection in the smart picker.

References

Top comments (0)