解决方法
正如Doug所说,你需要在Task中运行它
以下是您需要如何实现它的提示
- 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
- // ...
- }
- }
- });
有关如何实现它的更多信息,您可以检查在我回答此https://github.com/udacity/and-nd-firebase/issues/41后7天打开的这个github问题