nguyenhoanglam / ImagePicker

A customizable library for selecting images on the device.
Apache License 2.0
598 stars 158 forks source link

How to call launcher in java project? #145

Closed aerocube-tech closed 1 year ago

aerocube-tech commented 2 years ago

Can I use this library in java project? if yes then how?

yasdeveloper commented 1 year ago

+1

Pocus76 commented 1 year ago

Hi,

Here's what the author replied to me a few months ago :

For any Java projects, you can start image picker like this:

ImagePickerConfig config = new ImagePickerConfig();
config.setMaxSize(3);
Intent intent = ImagePickerLauncher.Companion.createIntent(requireContext(), config);
startActivityForResult(intent, 100);

and handle result like this:


@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == Activity.RESULT_OK) {
ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.EXTRA_IMAGES);
if (!images.isEmpty()) {
Glide.with(requireContext())
.load(images.get(0).getUri())
.into(binding.imageView);
}
}

}


> 
> In the future, this library will only focus on Kotlin project and I highly recommend you to switch to Kotlin right now.