I have an application that in a fragment takes pictures with the camera or the load from the gallery, until there all right, it reaches the camera and also lets me select the photo from the gallery.
The problem is that I want to show next the photo taken / image selected in another fragment with a couple of buttons
In summary, I would like to pass the photo as a parameter to another fragment, I read that it can be with bundle
, but it is very confusing for me to do it and where.
I leave the code that calls the camera, the gallery, and where I keep the image
private void navigateToCamera() {
Intent nativeCameraIntent = new Intent().setClass(getActivity(), NativeCameraActivity.class);
// Start the Intent
startActivityForResult(nativeCameraIntent, RESULT_LOAD_PHOTO);
}
public void loadImageFromGallery() {
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == getActivity().RESULT_OK && null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imgDecodableString = cursor.getString(columnIndex);
cursor.close();
ImageView imgView = (ImageView) getView().findViewById(R.id.faceImg);
// Set the Image in ImageView after decoding the String
imgView.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
} else if (requestCode == RESULT_LOAD_PHOTO && resultCode == getActivity().RESULT_OK && null != data) {
ImageView imgView = (ImageView) getView().findViewById(R.id.faceImg);
// Set the Image in ImageView after decoding the String
imgView.setImageBitmap(BitmapFactory.decodeFile(data.getStringExtra("imageUri")));
} else {
Toast.makeText(getContext(), R.string.no_photo_selected, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_LONG).show();
}
}
Thank you!