Skip to content

Repository files navigation

ImagePicker Android Library

Android library that can be used as quick solution to ImagePicker feature implementation.

Features

  • 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)

Translations

LanguageTranslation Coverage
English100%
Hebrew100%
Ukrainian100%

Implementation

  1. In project-level gradle add new maven repository:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
  1. In app-level gradle add new implementation:
dependencies {
implementation 'com.github.ShiftHackZ:ImagePicker:v2.0'
}
  1. Create file provider_path.xml in res/xml folder:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-pathname="media"path="." />
<external-pathname="external_files"path="."/>
</paths>
  1. In your AndroidManifest.xml add the file provider inside the <application tag:
<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>
  1. 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" />
  1. In order to receive images, implement ImagePickerCallback in 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
}
}
}
}
  1. 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()
  1. Finally, launch your ImagePicker:
imagePicker.launch(context)

Screenshots

Credits

About

ImagePicker Kotlin Android Library

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages