Firebase云存储task.getResult()。getDownloadUrl在Android中不起作用

时间:2020-04-01 09:56:03

标签: java android firebase-storage

Uri resultUri = result.getUri();
String current_userID = firebaseUser.getUid();

StorageReference filePath = mImageStorage.child("profile_images").child( current_userID + ".jpg");
filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
        if (task.isSuccessful()) {
            String downloadUrl = task.getResult().getDownloadUrl.toString();

            databaseReference.child("image").setValue(downloadUrl).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    if (task.isSuccessful()) {
                        mProgressDialog.dismiss();
                        Toast.makeText(AccountSettings.this, "Success Uploading", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        } else {
            Toast.makeText(AccountSettings.this, "Error in Uploading", Toast.LENGTH_SHORT).show();
            mProgressDialog.dismiss();
        }
    }
});

getDownloadUrl不能在其下方显示红线,或者是downloadUrl需要为其添加一种方法

1 个答案:

答案 0 :(得分:0)

  String downloadUrl = task.getResult().getDownloadUrl.toString();

应该是

  String downloadUrl = task.getResult().getDownloadUrl().toString();