coomar2841 / image-chooser-library

An Easy Image/Video Chooser Library for your Android Apps
646 stars 193 forks source link

Picking from gallery works great!! Capture doesn't with "Could't process a null file" #61

Closed fwhenin closed 9 years ago

fwhenin commented 9 years ago

my code for the two is very similar

private void displayImagePicker(int type){
        chooserType = type;
        imageChooserManager = new ImageChooserManager(this, type, "AutosoftFlexMobile", false);
        imageChooserManager.setImageChooserListener(this);
        try {
            imageChooser = imageChooserManager.choose();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == getActivity().RESULT_OK &&
                (requestCode == ChooserType.REQUEST_PICK_PICTURE ||
                        requestCode == ChooserType.REQUEST_CAPTURE_PICTURE)) {
            chooserType = requestCode;
            if (imageChooserManager == null){
                reinitializeImageChooser();
            }
            imageChooserManager.submit(requestCode, data);
        }

        super.onActivityResult(requestCode, resultCode, data);
    }

So everything is good for picking a picture from gallery, but when I use the camera, I take a picture, hit 'Save' then it goes to a blank screen, the reason is 'Couldn't process a null file' then the app crashes. any help would be great

fwhenin commented 9 years ago

Update: I got it not to crash..but still a null image gets passed

coomar2841 commented 9 years ago

You should save the image path, and re-initialize it with that. This should fix it.

filePath = imageChooserManager.choose();

imageChooserManager.reinitialize(filePath);

fwhenin commented 9 years ago

well the filePath during reinitialize is null for both after the user selects or captures an image

fwhenin commented 9 years ago

''' private void reinitializeImageChooser() { imageChooserManager = new ImageChooserManager(this, chooserType, "AutosoftFlexMobile", false); imageChooserManager.setImageChooserListener(this); imageChooserManager.reinitialize(imageChooser); // imageChooser here is always null } '''

coomar2841 commented 9 years ago

Could you try the sample app and see if it's still the same problem? If yes, then I can look into this.

fwhenin commented 9 years ago

I tried it...and it works there. but my code is inside a fragment not an activity

fwhenin commented 9 years ago

this is definitely something I'm doing, I just don't know what it is lol

coomar2841 commented 9 years ago

Ok, So, first thing, is probably because your activity is being destroyed. When you call this,

filePath = imageChooserManager.choose();

Can you check if at this point, it is null in the logs?

fwhenin commented 9 years ago

it's not null there...it's null at reinitialize

fwhenin commented 9 years ago

I'm looking now into using onSaveInstanceState and saving it there.

fwhenin commented 9 years ago

GOT IT

''' @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState);

    outState.putString("imageChooser", imageChooser);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (savedInstanceState != null){
        imageChooser = savedInstanceState.getString("imageChooser", null);
    }

}

'''

had to save the imageChooser and get it from the instancestate