Android library that can be used as quick solution to ImagePicker feature implementation.
- Permission handle requests
- Camera photo picker
- Gallery single photo picker
- Gallery multiple photo picker
- Custom gallery picker, supports multiple selection (for old non-AOSP Android ROMs that does not support multiple selection intent)
| Language | Translation Coverage |
|---|---|
| English | 100% |
| Hebrew | 100% |
| Ukrainian | 100% |
- In project-level gradle add new maven repository:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}- In app-level gradle add new implementation:
dependencies {
implementation 'com.github.ShiftHackZ:ImagePicker:v2.0'
}- Create file
provider_path.xmlinres/xmlfolder:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-pathname="media"path="." />
<external-pathname="external_files"path="."/>
</paths>- In your
AndroidManifest.xmladd the file provider inside the<applicationtag:
<providerandroid:name="androidx.core.content.FileProvider"android:authorities="${applicationId}.provider"android:exported="false"android:grantUriPermissions="true">
<meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/provider_path" />
</provider>- Add required permissions
<uses-permissionandroid:name="android.permission.CAMERA" />
<uses-permissionandroid:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"android:maxSdkVersion="32" />
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"android:maxSdkVersion="29" />
- In order to receive images, implement
ImagePickerCallbackin your Fragment/Activity or as object:
classMainActivity : AppCompatActivity(), ImagePickerCallback {
overridefunonImagePickerResult(result:PickedResult) {
when (result) {
PickedResult.Empty-> {
// No file was selected, noting to do
}
isPickedResult.Error-> {
val throwable = result.throwable
// Some error happened, handle this throwable
}
isPickedResult.Multiple-> {
val pickedImages = result.images
val files = pickedImages.map { it.file }
// Selected multiple images, do whatever you want with files
}
isPickedResult.Single-> {
val pickedImage = result.image
val file = pickedImage.file
// Selected one image, do whatever you want with file
}
}
}
}- Create an instance of ImagePicker using ImagePicker.Builder(), which require 2 mandatory params: current Activity and ImagePickerCallback:
val imagePicker =ImagePicker.Builder(this.packageName +".provider", this)
.useGallery(true) // Use gallery picker if true
.useCamera(true) // Use camera picker if true
.autoRotate(true) // Returns 0 degress rotated images, instead of exif-rotated images if true
.multipleSelection(true) // Allow multiple selection in gallery picker
.minimumSelectionCount(2) // Defines min count of GallerySelector.CUSTOM multiple selection gallery picker
.maximumSelectionCount(3) // Defines max count of GallerySelector.CUSTOM multiple selection gallery picker
.galleryPicker(GalleryPicker.CUSTOM) // Available values: GalleryPicker.NATIVE, GalleryPicker.CUSTOM
.build()- Finally, launch your ImagePicker:
imagePicker.launch(context)- Developer: Dmitriy Moroz
- E-Mail: dmitriy@moroz.cc


