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/FilePickerREADME
📁 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.
🚀 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 = 
🎯 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
-
Package and Class Changes:
The package has changed fromcom.nareshchocha.filepickerlibrary.uitocom.nareshchocha.filepickerlibrary. -
Removal of
BuilderClass:
TheBuilderclass is no longer needed. The new code utilizesActivityResultContractfor handling file picker actions. -
Introduction of
ActivityResultContracts:
File picker operations are now handled by specificActivityResultContractclasses, such asImageCapture,VideoCapture, andPickMedia. -
Logging Support:
A newisLoggingEnabledflag 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
- 📧 chochanaresh0@gmail.com
- 💬 Join our Slack
- Buy me a Coffee
📄 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.
