AndroidFilePicker
AndroidFilePicker is android library which will help you to pick any type of media file in your application. No need to manage any kind of extra permission or result method override. Just create library class instance and use it or also modify ui as your requirement.
Features:
- Capture Camera Image
- Pick Gallery Image Single or Multiple
- Crop Image (Crop image based on provided aspect ratio or let user choose one)
- Compress Image (Compress image based on provided compress quality, resolution and format)
- Handle all runtime permission for camera
- Does not require storage permission to pick gallery image or capture new image.
- Capture Camera Video
- Pick Video from Gallery
- Pick Specific type of document user need to specify pick document type
Usage
- Add the JitPack repository to your project level build file
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
- Add the dependency to your app level build file
dependencies {
implementation 'com.github.DhavalBaldhaa:AndroidFilePicker:Tag'
}
- Add Provider in manifest file
- Create AndroidFilePicker instance and show bottom-sheet file picker, Add callback method for retrieve result or error message
AndroidFilePicker.with(APPLICATION_ID)
.type(selectionType)
.enableDocumentWithOriginalName()
.callBack(object : FilePickerCallback {
override fun onSuccess(media: Media?) {
handleSelectedMedia(media)
}
override fun onSuccess(mediaList: ArrayList<Media>?) {
handleSelectedMedia(mediaList)
}
override fun onError(error: String?) {
val errorMessage = error ?: "Something Went Wrong"
Toast.makeText(this@MainActivity, errorMessage, Toast.LENGTH_SHORT)
.show()
}
})
.start(supportFragmentManager)
Customization
Choose required file type for your file picker selection options (Optional)
- ALL
- For all option capture image, pick image, capture video and pick video
Default selected, if not passed anything file picker works with default value
- For all option capture image, pick image, capture video and pick video
- IMAGE
- For capture image from camera and pick image from gallery
- VIDEO
- For capture video from camera and pick video from gallery
- CAPTURE_IMAGE
- For capture image from camera
- CAPTURE_VIDEO
- Capture video from camera
- PICK_IMAGE
- Select image from gallery
- PICK_VIDEO
- Select video from gallery
- TAKE_IMAGE_VIDEO
- Capture image and video from camera
- PICK_IMAGE_VIDEO
- Select image and video from gallery
- PICK_DOCUMENT
- Select any type of file as document format
AndroidFilePicker.with(APPLICATION_ID)
.type(selectionType)
.start(supportFragmentManager)
Theme Customization
- Added required color in your color.xml file
#F4F4F4
#ffffff
#000000
#000000
#ffffff
- Override bottomsheet theme as per your requirement
- Using custom layout xml file (You must need to add all ids with same view, Check demo for more details)
AndroidFilePicker.with(APPLICATION_ID, R.layout.custom_file_picker_layout)
.start(supportFragmentManager)
- Specify background resource and text colors for action buttons
AndroidFilePicker.with(APPLICATION_ID)
.updateTheme(
R.drawable.button_bg,
R.color.colorPrimary,
R.drawable.button_bg_primary,
R.color.white
)
.start(supportFragmentManager)
Methods for enable additional functionality
Method Name | Description |
---|---|
type(type: FileSelectionType) | Specify file selection option |
enableDirectAction() | For required direct selection option, Like if you want to direct open camera for capure image and not required to show filepicker ui |
enableCrop | Enable Cropping functionality and let user choose aspect ratio, By Default crop is disable (You can visit uCrop lib for customize cropping theme) |
crop(x: Float, y: Float) | Enable Cropping functionality with fixed Aspect Ratio |
cropSquare() | Crop square image, its same as crop(1f, 1f) |
maxCropResultSize(width: Int, height: Int) | Final image resolution will be less than width x height |
compressQuality(quality: Int) | Specify image compress quality. In 0 to 100 value, 100 means original image |
compressedFormat(format: CompressFormat) | Set compressed format, like JPEG, PNG, WEBP |
setResolutionConstraint(width: Int, height: Int) | Final compressed image resolution will be less than width x height |
pickDocumentType(type: String) | Specify selection document type, "*/*" default value Like "application/pdf - Only allow to select PDF File "image/* - Only allow to select image file as document |
enableMultiSelection() | Required when you want to selected multiple image from gallery |
enableDocumentWithOriginalName() | Required when you want to select document file with original file name, Default document will select with unique name |
Contribution
- Bug reports and pull requests are welcome.
- Make sure you use square/java-code-styles to format your code.