This library is designed to simplify the process of selecting and retrieving media files from an Android device, and supports media capture for images and videos.
How to add dependencies
Groovy
allprojects {
repositories {
mavenCentral() // For FilePicker library, this line is enough.
}
}
dependencies {
// ...
implementation 'io.github.chochanaresh:filepicker:$libVersion'
// ...
}
kts
allprojects {
repositories {
mavenCentral() // For FilePicker library, this line is enough.
}
}
dependencies {
// ...
implementation ("io.github.chochanaresh:filepicker:$libVersion")
// ...
}
libs.versions.toml
[versions]
filepicker = "$libVersion"
[libraries]
filepicker = { group = "io.github.chochanaresh", name = "filepicker", version.ref = "filepicker" }
dependencies {
// ...
implementation(libs.filepicker)
// ...
}
private val launcher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
// Use the uri to load the image
val uri = it.data?.data!!
// Use the file path to set image or upload
val filePath= it.data.getStringExtra(Const.BundleExtras.FILE_PATH)
//...
// for Multiple picks
// first item
val first = it.data?.data!!
// other items
val clipData = it.data?.clipData
// Multiple file paths list
val filePaths = result.data?.getStringArrayListExtra(Const.BundleExtras.FILE_PATH_LIST)
//...
}
}
private ActivityResultLauncher launcher =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// Use the uri to load the image
Uri uri = result.getData().getData();
// Use the file path to set image or upload
String filePath = result.getData().getStringExtra(Const.BundleExtras.FILE_PATH);
//...
// for Multiple picks
// first item
Uri first = result.getData().getData();
// other items
ClipData clipData = result.getData().getClipData();
// Multiple file paths list
ArrayList<String> filePaths = result.getData().getStringArrayListExtra(Const.BundleExtras.FILE_PATH_LIST);
//...
}
}
});
Multiple option with BottomSheet Or Dialog
FilePicker.Builder(this)
.setPopUpConfig()
.addPickDocumentFile()
.addImageCapture()
.addVideoCapture()
.addPickMedia()
.build()
new FilePicker.Builder(this)
.setPopUpConfig(null)
.addPickDocumentFile(null)
.addImageCapture(null)
.addVideoCapture(null)
.addPickMedia(null)
.build();
Customize popup
//..
setPopUpConfig(
PopUpConfig(
chooserTitle = "Choose Profile",
// layoutId = 0, custom layout
mPopUpType = PopUpType.BOTTOM_SHEET,// PopUpType.BOTTOM_SHEET Or PopUpType.DIALOG
mOrientation = RecyclerView.VERTICAL // RecyclerView.VERTICAL or RecyclerView.HORIZONTAL
)
)
//..
.build()
//..
setPopUpConfig(
new PopUpConfig(
"Choose Profile",
null,// custom layout
PopUpType.BOTTOM_SHEET, // PopUpType.BOTTOM_SHEET Or PopUpType.DIALOG
RecyclerView.VERTICAL // RecyclerView.VERTICAL or RecyclerView.HORIZONTAL
)
)
//..
.build()
//..
addPickDocumentFile(
DocumentFilePickerConfig(
popUpIcon = R.drawable.ic_file,// DrawableRes Id
popUpText = "File Media",
allowMultiple = false,// set Multiple pick file
maxFiles = 0,// max files working only in android latest version
mMimeTypes = listOf("*/*"),// added Multiple MimeTypes
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
settingPermissionMessage = null,// set Permission setting Messag
),
)
//..
.build()
//..
addPickDocumentFile(
new DocumentFilePickerConfig(
null, // DrawableRes Id
null,// Title for pop item
true, // set Multiple pick file
null, // max files working only in android latest version
mMimeTypesList, // added Multiple MimeTypes
null, // set Permission ask Title
null, // set Permission ask Message
null, // set Permission setting Title
null // set Permission setting Messag
)
)
//..
.build()
//..
addImageCapture(
ImageCaptureConfig(
popUpIcon = R.drawable.ic_camera,// DrawableRes Id
popUpText = "Camera",
mFolder = File(),// set custom folder with write file permission
fileName = "image.jpg",
// It is not working correctly. However, it will Work on the same devices.
isUseRearCamera = true, // setting camera facing
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
settingPermissionMessage = null,// set Permission setting Messag
),
)
//..
.build()
//..
addImageCapture(
new ImageCaptureConfig(
R.drawable.ic_camera, // DrawableRes Id
null, // Title for pop item
null, // set custom folder with write file permission
null, // set custom File name
// It is not working correctly. However, it will Work on the same devices.
isUseRearCamera = true, // setting camera facing
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
settingPermissionMessage = null,// set Permission setting Messag
)
)
//..
.build()
//..
addVideoCapture(
VideoCaptureConfig(
popUpIcon = R.drawable.ic_video,// DrawableRes Id
popUpText = "Video",
mFolder=File(),// set custom folder with write file permission
fileName = "video.mp4",
maxSeconds = null,// set video duration in seconds
maxSizeLimit = null,// set size limit
isHighQuality = null,// set isHighQuality true/false
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
settingPermissionMessage = null,// set Permission setting Messag
),
)
//..
.build()
//..
addVideoCapture(
new VideoCaptureConfig(
R.drawable.ic_video,// DrawableRes Id
null, // Title for pop item
null, // set custom folder with write file permission
null, // set custom File name
null, // set video duration in seconds
null, // set size limit
null, // set isHighQuality true/false
null, // set Permission ask Title
null, // set Permission ask Message
null, // set Permission setting Title
null, // set Permission setting Messag
)
)
//..
.build()
//..
addPickMedia(
PickMediaConfig(
popUpIcon = R.drawable.ic_media,// DrawableRes Id
popUpText = "Video",
allowMultiple = false,// set Multiple pick file
maxFiles = 0,// max files working only in android latest version
mPickMediaType = ImageAndVideo,
askPermissionTitle = null, // set Permission ask Title
askPermissionMessage = null,// set Permission ask Message
settingPermissionTitle = null,// set Permission setting Title
settingPermissionMessage = null,// set Permission setting Messag
),
)
//..
.build()
//..
addPickMedia(
new PickMediaConfig(
R.drawable.ic_media,// DrawableRes Id
null, // Title for pop item
null, // set Multiple pick file
null, // max files working only in android latest version
null, // set PickMediaTypes
null, // set Permission ask Title
null, // set Permission ask Message
null, // set Permission setting Title
null, // set Permission setting Messag
)
)
//..
.build()
import com.nareshchocha.filepickerlibrary.models.PickMediaType
import com.nareshchocha.filepickerlibrary.models.PickMediaType;
- PickMediaType.ImageOnly
- PickMediaType.VideoOnly
- PickMediaType.ImageAndVideo
FilePicker.Builder(this)
.pickDocumentFileBuild(DocumentFilePickerConfig())
Customization DocumentFilePickerConfig
new FilePicker.Builder(this)
.pickDocumentFileBuild(new DocumentFilePickerConfig(null));
Customization DocumentFilePickerConfig
FilePicker.Builder(this)
.imageCaptureBuild(ImageCaptureConfig())
Customization ImageCaptureConfig
new FilePicker.Builder(this)
.imageCaptureBuild(new ImageCaptureConfig(null));
Customization ImageCaptureConfig
FilePicker.Builder(this)
.videoCaptureBuild(VideoCaptureConfig())
Customization VideoCaptureConfig
new FilePicker.Builder(this)
.videoCaptureBuild(new VideoCaptureConfig(null));
Customization VideoCaptureConfig
FilePicker.Builder(this)
.pickMediaBuild(PickMediaConfig())
Customization PickMediaConfig
new FilePicker.Builder(this)
.pickMediaBuild(new PickMediaConfig(null));
Customization PickMediaConfig
-keepclasseswithmembernames class com.nareshchocha.filepickerlibrary.models.**{
*;
}
-keepclassmembers class * extends androidx.appcompat.app.AppCompatActivity {
*;
}
- Library - Android Lollipop 5.0+ (API 21)
- Sample - Android Lollipop 5.0+ (API 21)
Contributions are always welcome!
For support, email chochanaresh0@gmail.com or join our Slack channel.
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.