由于taskSnapshot.getDownloadUrl()已失效,因此我按照firebase的帖子获取了URL
final StorageReference ref = storageRef.child("images/mountains.jpg");
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();
} else {
// Handle failures
// ...
}
}
});
但我想要
String downloadUri = taskSnapshot.getDownloadUrl().toString();
代替
Uri downloadUri = task.getResult();
我该怎么做?
答案 0 :(得分:0)
经过一些研究,我通过更改来了解答案:
String downloadUrii = downloadUri.toString();
将是解决方案