Reputation: 1
In fragment i need to upload image to server so for that i am using retrofit! Now i am using a library for capture an image from gallery & camera. but the problem is its not getting stored anywhere, I'm trying to getData in onActivityResult but it's not showing any kind of image path and error as well
Here is my code for Capturing image (gallery& Camera both) ->
public void takePicture() {
ImagePicker.with(getActivity())
//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)
.cameraOnly()
.start();
}
private void galleryIntent() {
ImagePicker.with(getActivity())
//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)
.galleryOnly()
.start();
}
Here i am trying to get image path in OnActivityResult ->
@Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data);
try{
uri = data.getData();
Log.d("ImagePath",uri.getPath());
image_invoice.setVisibility(View.VISIBLE);
image_invoice.setImageURI(uri);
imageuploadRx.setVisibility(View.INVISIBLE);
}catch (Exception exception){
}
}
Please anyone help me to get this image and save it in my interface so i could be able to upload this image path in server!!
I tried with if else conditions and also tried to call it direct in onCreate method but it's still didn't work !
Upvotes: 0
Views: 91
Reputation: 115
Probably you use getActivity to call the image picker, try to change 'getActivity()' into 'this'.
ImagePicker.with(this) <--- check this
.compress(1024)
.maxResultSize(1080, 1080)
.galleryOnly()
.start();
Reference Stack Overflow - onActivityResult is not being called in Fragment
Let me know if it works.
Upvotes: 0