Closed voghDev closed 2 years ago
A few more information and context in case it helps.
This code worked well allowing us to select a picture from Gallery in the mentioned devices:
pickImageLauncher.launch(
ImagePicker.with(requireActivity())
.maxResultSize(
1024,
1024,
false
)
.cropSquare()
.galleryOnly()
.galleryMimeTypes(mimeTypes = someMimeTypes)
.createIntent()
)
And this other code also worked well taking a picture with Camera:
pickImageLauncher.launch(
ImagePicker.with(requireActivity())
.maxResultSize(
1024,
1024,
false
)
.cropSquare()
.cameraOnly()
.galleryMimeTypes(mimeTypes = someMimeTypes)
.createIntent()
)
where pickImageLauncher
is:
private val pickImageLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// ...
}
}
I can provide a pull request updating the README file to make the documentation consistent
Where do you see this:
pickImageLauncher.launch(
?
What I see in the readme.md is:
If you want both Camera and Gallery:
Kotlin
ImagePicker.with(this)
//...
.createIntentFromDialog { launcher.launch(it) }
Additionally, I see that .compress(). Is there a replacement for it? I'm using maxResultSize but am not sure if it's the best option
compress
wasn't work properly so, maxResultSize
is enough, I'd say.
:heavy_check_mark: I finally solved my issue. I'll tell you how. Something really curious was happening :scream: :point_down:
I tried the code on the first comment because the sample code wasn't working for me. When I launched it, nothing was working. A dialog to choose between Camera and Gallery was supposed to appear, and it wasn't appearing :point_down:
ImagePicker.with(requireActivity())
.maxResultSize(
1024,
1024,
false
)
.cropSquare()
.galleryMimeTypes(mimeTypes = someMimeTypes)
.createIntentFromDialog { pickImageLauncher.launch(it) }
After introspecting in the library code and setting some breakpoints, I found a curious value for imageProvider
in ImagePicker::createIntentFromDialog
function:
the imageProvider
variable had FRONT_CAMERA
as value instead of BOTH
, which is the initial value and the expected one I need.
I can't guess why this happened :sweat_smile: I don't see FRONT_CAMERA
assigned to imageProvider
anywhere, but in the Intent extras.
Anyway, all I needed to do was to force imageProvider
to have BOTH
as value. Code is as follows:
ImagePicker.with(requireActivity())
.maxResultSize(
1024,
1024,
false
)
.provider(ImageProvider.BOTH) // This line is the key
.cropSquare()
.galleryMimeTypes(mimeTypes = someMimeTypes)
.createIntentFromDialog { pickImageLauncher.launch(it) }
Now the dialog is showing and everything works again :slightly_smiling_face: Thank you very much
Hello!
first of all, thanks for this awesome library, it's doing a great task. I just want to ask a question about the documentation in the README file. The example code provided is the following :point_down:
it states: If you want both Camera and Gallery
But in my case, the code directly uses the camera instead of allowing me to choose between camera and Gallery. It is working well though. :question: :grey_question: Is this the intended behaviour? :question: :grey_question:
Tested devices were Xiaomi Mi A3 (Android 11), Xiaomi Mi A2 Lite (Android 10) and Nexus 5X emulator (Api 26).
Additionally, I see that
.compress()
was removed. Is there a replacement for it? I'm usingmaxResultSize
but am not sure if it's the best optionThank you so much!