Android - Firebase - TaskSnapshot -方法应该只在私有范围内访问吗?

时间:2022-02-02 20:05:05

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

工作一切都好…直到我从3个月的休息中回来工作,并将我的Firebase从9.8升级到10.0.1

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

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

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().

我现在得到的错误是关于tasksnapshol . getdownloadurl()。

Android Studio underlines that line in red and says:

Android Studio用红色强调这一行,并说:

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.

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

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

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

Android - Firebase - TaskSnapshot -方法应该只在私有范围内访问吗?

2 个解决方案

#1


63  

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.

这个把戏对我起作用了。如果这个问题与这个bug报告有关,那么应该在2.4中修复它。

#2


0  

I had the same problem and it was gone when I have updated my Firebase version. I was using 10.0.1 and now I am using 11.0.0

我遇到了同样的问题,当我更新我的Firebase版本时,它就消失了。我用的是10。1,现在用的是11。0

#1


63  

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.

这个把戏对我起作用了。如果这个问题与这个bug报告有关,那么应该在2.4中修复它。

#2


0  

I had the same problem and it was gone when I have updated my Firebase version. I was using 10.0.1 and now I am using 11.0.0

我遇到了同样的问题,当我更新我的Firebase版本时,它就消失了。我用的是10。1,现在用的是11。0