本文介绍了taskSnapshot.getDownloadUrl()方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void uploadImageToFirebaseStorage() {
    StorageReference profileImageRef =
        FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");

    if (uriProfileImage != null) {
        progressBar.setVisibility(View.VISIBLE);
        profileImageRef.putFile(uriProfileImage)
            .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
                    progressBar.setVisibility(View.GONE);
                    profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    progressBar.setVisibility(View.GONE);
                    Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            });
    }
}

taskSnapshot.getDownloadUrl()方法不起作用,其下方显示红线

taskSnapshot.getDownloadUrl() method not working comes up with red line under it

推荐答案

编辑:请参见,说明为何此答案中的方法无效:

Edit: see this comment on why the approach in this answer doesn't work:

下面的原始答案...

Original answer below...

Firebase Storage API版本16.0.1中,使用taskSnapshot对象的getDownloadUrl()方法已更改.现在您可以使用了,

In Firebase Storage API version 16.0.1,the getDownloadUrl() method using taskSnapshot object has changed.now you can use,

taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()

从Firebase存储中获取下载URL.

to get download url from the firebase storage.

这篇关于taskSnapshot.getDownloadUrl()方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 03:43