本文介绍了Android Firebase getDownloadUrl();无法解析符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我解决这个错误吗?getDownloadUrl();说无法解析getDownloadUrl()的符号变量.我知道不赞成使用getDownloadUrl();,我尝试阅读更新的文档,但是我有点新意,我不明白如何在不破坏所有内容的情况下编辑我的代码.

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 the updated documentation but i'm a little bit new at this and i don't understand how to edit my code without ruining everything.

        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            if (resultCode == RESULT_OK) {

                final Uri resultUri = result.getUri();
                String user_id=mAuth.getCurrentUser().getUid();
                final StorageReference filepath=storageProfileImageRef.child(user_id + ".jpg");

                filepath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                        if(task.isSuccessful()){
                           String downloadUri = task.getResult().getdownloadUrl.toString();



                            Toast.makeText(SETTINGSACTIVITYSCREEN.this, "saving profile image to database", Toast.LENGTH_SHORT).show();




                            getUserDataBaseRefrence.child("user_image").setValue(downloadUri).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {
                                    Toast.makeText(SETTINGSACTIVITYSCREEN.this, "image uplaod success", Toast.LENGTH_SHORT).show();

                                }
                            });

                        }
                        else{
                            Toast.makeText(SETTINGSACTIVITYSCREEN.this, "error", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                Exception error = result.getError();
            }
        }
    }
}

推荐答案

getDownloadUrl 不再存在.

看看下面的代码是否对您有用.

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
            // ...
        }
    }
});

这篇关于Android Firebase getDownloadUrl();无法解析符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-30 08:31