SkillAgentSearch skills...

FilePicker

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.

Install / Use

/learn @ChochaNaresh/FilePicker

README

📁 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 6.0 (API 23) 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.
View on GitHub
GitHub Stars172
CategoryCustomer
Updated1mo ago
Forks18

Languages

Kotlin

Security Score

100/100

Audited on Feb 17, 2026

No findings