Android - Firebase - TaskSnapshot - 只能在私人范围内访问方法? [英] Android - Firebase - TaskSnapshot - Method should only be accessed within private scope?

查看:206
本文介绍了Android - Firebase - TaskSnapshot - 只能在私人范围内访问方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切都很好,直到我从3个月的休息时间回来工作,并将我的Firebase从9.8更新到10.0.1



现在我所有的调用 TaskSnapshot 给我一个错误。



以下是可以正常工作的示例代码:

  OnSuccessListener< UploadTask.TaskSnapshot> ()添加一个新的文件,并将其添加到文件名中,然后添加一个新的文件。 。getDownloadUrl()的toString()); 

numberOfCallbacks ++;
if(numberOfFiles == numberOfCallbacks){
currentUpload = false;
onClickSendAlert(sendingView);
}
}
};

现在我得到的错误是关于 taskSnapshot.getDownloadUrl() code $。

Android Studio强调了红线,并说:


这个方法只能从测试或私人范围内访问。

有人可以解释为什么会发生这种情况吗?我一直在研究整天两天,现在不能为我的生活弄明白(尴尬)。



这个代码是值得的用于将文件上传到Firebase存储,然后在完成时( OnSuccess ),获取下载URL并将其存储在Firebase数据库中。在我更新到10.0.1之前,这很好用。我在另一个模块的下载任务中遇到了同样的错误。



下面是一个截图,让您更好地了解我的情况:

相关,则应该是固定在2.4。


Everything was working great... until I came back to work from a 3 month break and updated my Firebase from 9.8 to 10.0.1

Now all of my calls to TaskSnapshot are giving me an error.

Here is the example code that worked fine before:

OnSuccessListener<UploadTask.TaskSnapshot> successListener = new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        attachments.add(fileName + "*-*" + taskSnapshot.getDownloadUrl().toString());

        numberOfCallbacks++;
        if (numberOfFiles == numberOfCallbacks) {
            currentUpload = false;
            onClickSendAlert(sendingView);
        }
    }
};

The error that I now get is regarding taskSnapshot.getDownloadUrl().

Android Studio underlines that line in red and says:

This method should only be accessed from tests or within private scope

Can someone explain why this is happening? I have been researching all day for two days straight now and can't for the life of me figure this out (embarrassing).

For what it's worth, this code is used to upload a file to Firebase Storage, then when it is complete (OnSuccess), it gets the download URL and stores it in the Firebase Database. This worked great before I updated to 10.0.1. I get the same error on my download tasks in another module.

Here is a screenshot to give you a better visual of my situation:

解决方案

The problem seems to be caused by an overzealous Lint check. Try something like this:

@SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();

This trick worked for me. If the problem's related to this bug report, then it should be fixed in 2.4.

这篇关于Android - Firebase - TaskSnapshot - 只能在私人范围内访问方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆