Android firebase getDownloadUrl(); cannot resolve symbol

前端 未结 2 1301
傲寒
傲寒 2021-01-16 12:35

can you help me with this error. getDownloadUrl(); says cannot resolve symbol variable for getDownloadUrl(). I know that getDownloadUrl();is deprecated and i tried reading t

相关标签:
2条回答
  • 2021-01-16 12:57

    getDownloadUrl no longer exists.

    Take a look at below code if it works for you.

    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
                // ...
            }
        }
    });
    
    0 讨论(0)
  • 2021-01-16 13:05

    Replace the code to:

    String downloadUri = task.getResult().getdownloadUrl().toString();
    

    instead of

    String downloadUri = task.getResult().getdownloadUrl.toString();
    
    0 讨论(0)
提交回复
热议问题