如何解决此任务Snapshot.getDownloadUrl()。toString();使用Firebase存储的新方法

时间:2018-09-02 10:28:01

标签: java firebase firebase-storage

由于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();

我该怎么做?

1 个答案:

答案 0 :(得分:0)

经过一些研究,我通过更改来了解答案:

String downloadUrii = downloadUri.toString();

将是解决方案