Skip to content

All-in-one file and media picker library for Android. This library simplifies selecting, capturing, and retrieving documents, images, and videos from Android devices. It supports both single and multiple selections, camera capture, and is fully compatible with modern Android APIs.

License

Notifications You must be signed in to change notification settings

ChochaNaresh/FilePicker

Repository files navigation

πŸ“ File Picker Library for Android

A customizable, modern media/document picker for Android with support for image and video capture, file selection, and Jetpack's ActivityResult API integration.

Maven Central Build API Language Kotlin


πŸš€ Features

  • πŸ“‚ Document Picker
  • πŸ“· Image Capture
  • πŸŽ₯ Video Capture
  • πŸ–ΌοΈ Pick Images & Videos from Gallery
  • βš™οΈ Fully customizable popups
  • 🧩 Built-in ActivityResultContracts for Kotlin & Java

πŸ“¦ Installation

Gradle (Groovy)

repositories {
    mavenCentral()
}

dependencies {
    implementation 'io.github.chochanaresh:filepicker:<latest-version>'
}

Gradle (Kotlin DSL)

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.chochanaresh:filepicker:<latest-version>")
}

Version

latest-version = libVersion

🎯 FilePickerResultContracts (Jetpack ActivityResult APIs)

Use the built-in contracts for simplified integration using Jetpack's registerForActivityResult.

βœ… Setup Example

private val launcher = registerForActivityResult(FilePickerResultContracts.ImageCapture()) { result ->
    if (result.errorMessage != null) {
        Log.e("Picker", result.errorMessage ?: "")
    } else {
        val uri = result.selectedFileUri
        val filePath = result.selectedFilePath
    }
}

πŸ“‹ Available Contracts

Contract Description
ImageCapture() Launch camera and capture image
VideoCapture() Record video using camera
PickMedia() Select image/video from gallery
PickDocumentFile() Choose document(s)
AllFilePicker() Show a popup to choose between multiple
AnyFilePicker() Automatically selects contract based on config

🧠 Usage Examples

πŸ“· Image Capture

val launcher = registerForActivityResult(FilePickerResultContracts.ImageCapture()) { result -> }
launcher.launch(ImageCaptureConfig())

🎬 Video Capture

val launcher = registerForActivityResult(FilePickerResultContracts.VideoCapture()) { result -> }
launcher.launch(VideoCaptureConfig())

πŸ–ΌοΈ Pick Image/Video

val launcher = registerForActivityResult(FilePickerResultContracts.PickMedia()) { result -> }
launcher.launch(PickMediaConfig(allowMultiple = true))

πŸ“„ Pick Documents

val launcher = registerForActivityResult(FilePickerResultContracts.PickDocumentFile()) { result -> }
launcher.launch(DocumentFilePickerConfig(allowMultiple = true))

πŸ”„ Popup UI for All Options

val launcher = registerForActivityResult(FilePickerResultContracts.AllFilePicker()) { result -> }
launcher.launch(PickerData())

🧠 Dynamic Picker (AnyFilePicker)

val launcher = registerForActivityResult(FilePickerResultContracts.AnyFilePicker()) { result -> }
launcher.launch(ImageCaptureConfig()) // Or any config subclass

πŸ“˜ FilePickerResult

data class FilePickerResult(
    val selectedFileUri: Uri? = null,
    val selectedFileUris: List<Uri>? = null,
    val selectedFilePath: String? = null,
    val selectedFilePaths: List<String>? = null,
    val errorMessage: String? = null
)

βš™οΈ Config Options

πŸ“„ DocumentFilePickerConfig

DocumentFilePickerConfig(
    popUpIcon = R.drawable.ic_file,
    popUpText = "File Media",
    allowMultiple = true,
    maxFiles = 10,
    mMimeTypes = listOf("application/pdf", "image/*")
)

πŸ“· ImageCaptureConfig

ImageCaptureConfig(
    popUpIcon = R.drawable.ic_camera,
    popUpText = "Camera",
    mFolder = File(cacheDir, "Images"),
    fileName = "image_${System.currentTimeMillis()}.jpg",
    isUseRearCamera = true
)

πŸŽ₯ VideoCaptureConfig

VideoCaptureConfig(
    popUpIcon = R.drawable.ic_video,
    popUpText = "Video",
    mFolder = File(cacheDir, "Videos"),
    fileName = "video_${System.currentTimeMillis()}.mp4",
    maxSeconds = 60,
    maxSizeLimit = 20L * 1024 * 1024,
    isHighQuality = true
)

πŸ–ΌοΈ PickMediaConfig

PickMediaConfig(
    popUpIcon = R.drawable.ic_media,
    popUpText = "Pick Media",
    allowMultiple = true,
    maxFiles = 5,
    mPickMediaType = PickMediaType.ImageAndVideo
)

PickMediaType Options

PickMediaType.ImageOnly
PickMediaType.VideoOnly
PickMediaType.ImageAndVideo

πŸŽ›οΈ PickerData & PopUpConfig

val pickerData = PickerData(
    mPopUpConfig = PopUpConfig(
        chooserTitle = "Choose Option",
        mPopUpType = PopUpType.BOTTOM_SHEET,
        mOrientation = Orientation.VERTICAL,
        cornerSize = 12f
    ),
    listIntents = listOf(
        ImageCaptureConfig(),
        VideoCaptureConfig(),
        PickMediaConfig(),
        DocumentFilePickerConfig()
    )
)

Migration Guide: FilePicker Library

Overview

This guide outlines the changes from the old code to the new FilePicker implementation, focusing on the transition from the Builder pattern to ActivityResultContract.

Key Changes

  1. Package and Class Changes:
    The package has changed from com.nareshchocha.filepickerlibrary.ui to com.nareshchocha.filepickerlibrary.

  2. Removal of Builder Class:
    The Builder class is no longer needed. The new code utilizes ActivityResultContract for handling file picker actions.

  3. Introduction of ActivityResultContracts:
    File picker operations are now handled by specific ActivityResultContract classes, such as ImageCapture, VideoCapture, and PickMedia.

  4. Logging Support:
    A new isLoggingEnabled flag allows enabling logging in the contracts for debugging.

Migration Steps

1. Remove Builder Pattern

The Builder class is no longer needed. You should transition to using ActivityResultContracts instead.

2. Use ActivityResultContracts

You can now handle file picker actions with specific contracts. For example:

  • Old Code:
    fun imageCaptureBuild(mImageCaptureConfig: ImageCaptureConfig?): Intent =
        ImageCaptureActivity.getInstance(context, mImageCaptureConfig)
  • New Code:
    val imageCaptureResult = registerForActivityResult(FilePickerResultContracts.ImageCapture()) { result ->
    // Handle result
    }

πŸ“± Compatibility

  • Android 5.0 (API 21) and above
  • Supports Kotlin & Java

πŸ™Œ Contributing

Contributions are always welcome!
Please fork and submit PRs with clear commit history.


β˜• Support


πŸ“„ License

Copyright 2023 Naresh chocha

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

All-in-one file and media picker library for Android. This library simplifies selecting, capturing, and retrieving documents, images, and videos from Android devices. It supports both single and multiple selections, camera capture, and is fully compatible with modern Android APIs.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages