Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use image picker on fragment #85

Open
malayariau opened this issue Nov 27, 2022 · 1 comment
Open

how to use image picker on fragment #85

malayariau opened this issue Nov 27, 2022 · 1 comment
Assignees
Labels
help wanted Extra attention is needed

Comments

@malayariau
Copy link

malayariau commented Nov 27, 2022

hello i am implement this code to pick image from camera or gallery

btn_pilih_ktp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImagePicker.with(getActivity())
                        .crop()
                        // .cropSquare()
                        .maxResultSize(1048, 1048, true)
                        .createIntentFromDialog((Function1) (new Function1() {
                            public Object invoke(Object var1) {
                                this.invoke((Intent) var1);
                                return Unit.INSTANCE;
                            }

                            public final void invoke(@NotNull Intent it) {
                                Intrinsics.checkNotNullParameter(it, "it");
                                launcher_ktp.launch(it);
                            }
                        }));
            }
        });
ActivityResultLauncher<Intent> launcher_ktp =
            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), (ActivityResult result) -> {
                if (result.getResultCode() == RESULT_OK) {

                    Uri uri = result.getData().getData();
                    uri_ktp = uri;

                    // Use the uri to load the image
                    img_ktp .setImageURI(null);
                    img_ktp  .setImageURI(uri);


                } else if (result.getResultCode() == ImagePicker.RESULT_ERROR) {
                    ImagePicker.Companion.getError(result.getData()) ;
                }
            });

it's can be run without any problem in activity. but we need load pick and load image to imageview in fragment and can't use with this methode. how to solve this problem

@Drjacky Drjacky self-assigned this Nov 28, 2022
@Drjacky Drjacky added the help wanted Extra attention is needed label Nov 28, 2022
@Drjacky
Copy link
Owner

Drjacky commented Nov 28, 2022

Please attach a sample project (includes your attempt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants