When the button is clicked, a photo from the gallery is taken (the addPhoto method); in the onActivityResult method onActivityResult photo is uploaded to Firebase Storage with the name of the key received.
Then, according to the documentation , to obtain the URL of the image, use the continueWithTask method, inside which the resulting URL is placed in the Firebase Database.
Problem: the continueWithTask method does not start (checked with logs + its URL value remains null). What is the error or how else can you return from the URL method (a variable of type Uri)?
Code:
public void addPhoto(View view) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, GALLERY_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1 && data != null) { final DatabaseReference newDatabaseReference = FirebaseDatabase.getInstance().getReference("items").push(); donosId = newDatabaseReference.getKey(); final StorageReference imageRef = FirebaseStorage.getInstance().getReference().child("images/" + donosId + ".jpg"); imageRef.putFile(data.getData()).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() { @Override public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } // Continue with the task to get the download URL return imageRef.getDownloadUrl(); } }).addOnCompleteListener(new OnCompleteListener<Uri>() { @Override public void onComplete(@NonNull Task<Uri> task) { if (task.isSuccessful()) { Uri downloadUri = task.getResult(); String var = downloadUri.toString(); Item item = new Item(mNameEditText.getText().toString(), mSecNameEditText.getText().toString(), var, (int) System.currentTimeMillis()); newDatabaseReference.setValue(item); } } }); } }