GithubHelp home page GithubHelp logo

Comments (4)

nguyenhoanglam avatar nguyenhoanglam commented on August 20, 2024

You can custom my library to meet your expectation!
In ImagePickerActivity, modify onActivityResult method like this:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.REQUEST_CODE_CAPTURE) {
            if (resultCode == RESULT_OK) {
                if (fileTemp != null && fileTemp.exists()) {
                    MediaScannerConnection.scanFile(this,
                            new String[]{fileTemp.getAbsolutePath()}, null,
                            new MediaScannerConnection.OnScanCompletedListener() {
                                @Override
                                public void onScanCompleted(String path, Uri uri) {
                                    Log.v("MediaScanWork", "file " + path
                                            + " was scanned successfully: " + uri);

                                    Image image = new Image(0,"",path,false);
                                    ArrayList<Image> images = new ArrayList<Image>();
                                    images.add(image);

                                    Intent data = new Intent();
                                    data.putParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES, images);
                                    setResult(RESULT_OK, data);
                                    finish();
                                   // getDataWithPermission();
                                }
                            });
                }
            }
        }
    }

After you capture an image in SINGLE mode, the ImagePickerActivity will be finished and return the captured image!

Please feel free to ask me any question!

from imagepicker.

Rainer-Lang avatar Rainer-Lang commented on August 20, 2024

@YasirAmeen Is your question answered? If yes - please close this issue.

from imagepicker.

Rainer-Lang avatar Rainer-Lang commented on August 20, 2024

@nguyenhoanglam I think the question is answered.

from imagepicker.

Rajabsk avatar Rajabsk commented on August 20, 2024

Hi,
My project is capturing image from the camera and set it in ImageView. Later, it has to be uploaded to the database. Image picker from the gallery is working fine but am getting an error with camera intent. Can you please help me with correct code.

My code is as follows.

For Camera Intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
featuredImages_gallery = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
Uri uri = Uri.fromFile(new File(featuredImages_gallery.get(0).getPath()));
Picasso.with(AddPropertiesActivity.this).load(uri).into(img_gallery);
isFeaturedGallery = true;

}


Image Picker from gallery code:

ImagePicker.create(this)
.folderMode(true)
.folderTitle("Folder")
.imageTitle("Tap to select")
.multi()
.limit(5)
.showCamera(false)
.imageDirectory("Camera")
.start(REQUEST_FEATURED_PICKER_GALLERY);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_FEATURED_PICKER_GALLERY) {
if (resultCode == Activity.RESULT_OK && data != null) {
featuredImages_gallery = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
Uri uri = Uri.fromFile(new File(featuredImages_gallery.get(0).getPath()));
Picasso.with(AddPropertiesActivity.this).load(uri).into(img_gallery);
isFeaturedGallery = true;
}

}
}

Uploading data to server:
if (isFeaturedGallery) {
request.addParameter("place_gallery_image[]", featuredImages_gallery);
}

from imagepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.