Android image picker and camera app based on PixImagePixer library version 1.5.2 by Akshay Sharma.
- CameraX implementation
- ActivityResultContracts replace ActivityResult
Add it to your build.gradle with:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
and:
dependencies {
implementation 'com.github.yzzzd:PixProject:{latest version}'
}
val options = Options.init()
.setType(Options.Mode.Both) //Options.Mode.Camera or Options.Mode.Gallery
.setCount(3) //Number of images to restict selection count
Pix.open(this, options, activityResultLauncher)
or just use with minimal config
Pix.open(this, Options.Mode.Both, activityResultLauncher)
for fetching only a single picture.
Use ActivityResultContracts to get results
private var activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val returnValue = result.data?.getStringArrayListExtra(Pix.IMAGE_RESULTS)
if (returnValue?.isNotEmpty() == true) {
val imageFile = File(returnValue[0])
binding.imageView.setImageURI(imageFile.toUri())
}
}
}
Licensed under the Apache License, Version 2.0,