Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use this Imagepicker in fragment?

See original GitHub issue

Please give some example code to use imagepicker in fragment class. I got error:

                        .crop()	    			//Crop image(Optional), Check Customization for more option
                        .compress(1024)			//Final image size will be less than 1 MB(Optional)
                        .maxResultSize(1080, 1080)	//Final image resolution will be less than 1080 x 1080(Optional)

I got error on (this) that means it is not recognizing (this) and also getExternalFilesDir(). I think it is because we have to pass activity but we are in fragment.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

PickupAgency-Admincommented, Jan 11, 2022

It works fine in my app.


implementation 'com.github.dhaval2404:imagepicker:2.1'
compileSdkVersion 31
buildToolsVersion "31.0.0"

In your fragment

Create an activity result launcher:

private final ActivityResultLauncher<Intent> startForMediaPickerResult = registerForActivityResult(
        new ActivityResultContracts.StartActivityForResult(),
            result -> {
                Intent data = result.getData();
                if (data != null && result.getResultCode() == Activity.RESULT_OK) {
                    Uri resultUri = data.getData();
                else {
                    Toast.makeText(requireActivity(), ImagePicker.getError(data), Toast.LENGTH_SHORT).show();

Pick image

private void pickMedia() {
        String[] mimeTypes = {"image/png", "image/jpg", "image/jpeg"};
                .maxResultSize(800, 800)
                .createIntent(intent -> {
                    return null;
khchoudhary8commented, Nov 26, 2021

i have the same issue, do you have a resolution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selecting Image from gallery using fragment - android
I am trying to get image from gallery using fragment which is called from fragmentactivity but onActivityResult of the fragment class is not ......
Read more >
com.esafirm.imagepicker.features.ImagePickerFragment java ...
Best Java code snippets using com.esafirm.imagepicker.features.ImagePickerFragment (Showing top 20 results out of 315) · ImagePickerActivity.onBackPressed().
Read more >
Android Image Picker using Camera and Gallery. - Medium
Android Image Picker using Camera and Gallery. Implementation Utility of Custom ... Camera Fragment for Implement Camera using Camera X.
Read more >
ImagePicker - Akshay Kale
ImagePicker. Android ImagePicker library use to choose images from Gallery and also provide an option to capture image from camera.
Read more >
Taking Pictures In An Android Fragment Using Intents - AirPair
5 Capturing Activity Results In Fragments ... I next want to draw your attention to these lines: Uri fileUri = Uri.fromFile(photoFile); activity.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found