So I want to upload cover photo if user chosen or profile image if chosen on save btn
clicked
here is my UI design for better understanding.
for choosing image from gallery I did something like this:
private void chooseImage(int imgReqCode) {
// Defining Implicit Intent to mobile gallery
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(
intent,
"Select Image from here..."),
imgReqCode);
}
and this is onActivityResult code:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
checkAndSetImage(requestCode, COVER_IMG_REQUEST, resultCode, data, binding.coverPhoto, coverUri);
checkAndSetImage(requestCode, PROFILE_IMG_REQUEST, resultCode, data, binding.profilePhoto, profileUri);
}
And this is my checkAndSetImage
method :
private void checkAndSetImage(int requestCode, int PICK_IMAGE_REQUEST, int resultCode, Intent data, ImageView imageView, Uri filePath) {
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
// Get the Uri of data
filePath = data.getData();
try {
// Setting image on image view using Bitmap
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
// Log the exception
e.printStackTrace();
}
}
}
And this is my Uri 's which is declare as global :
private Uri coverUri, profileUri;
After that I am confused How can I upload that to firebase storage and get both or which is available's url in my firestore database
or According to you how can you upload 2 Images (1. Cover, 2. Profile) in firebase database accoriding to my layout