As Doug says, you will need to run it inside a Task
Here is a hint of how you need to implement it
final StorageReference ref = storageRef.child("your_REF");
uploadTask = ref.putFile(file);
Task<Uri> urlTask = uploadTask.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 ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
Uri downloadUri = task.getResult();
String downloadURL = downloadUri.toString();
} else {
// Handle failures
// ...
}
}
});
For more information about how to implement it, you can check this github question that was opened 7 days after I answered this https://github.com/udacity/and-nd-firebase/issues/41