问题描述
在gradle更新之前,一切正常,但稍后会弹出此错误.我已经参考了官方文件,并且提供了相同的代码.不接受getDownloadUrl()方法
Before gradle update everything worked fine, but later on this error popped up. I have referred to the official documents and it provides the same code.Not accepting the getDownloadUrl() method
我添加了最新的正确依赖项,并且gradle同步成功. app/build.gradle
I have added the correct dependency which is latest and the gradle sync is successful.app/build.gradle
这是firebase文档中提供的示例代码,与我的相同. Firebase助手
This is the sample code provided in firebase docs which is same as mine.Firebase Assistant
即使存在所有必需的东西,我也无法理解可能出了什么问题.自2天以来一直坚持下去,请提供帮助!
I'm unable to understand what could possibly go wrong even if all required things are present. Stuck on this since 2 days, please help!
推荐答案
正如Doug所指出的,UploadTask.getDownloadUrl()
已过时,因此请使用 StorageReference.getDownloadUrl().
As Doug pointed out, UploadTask.getDownloadUrl()
is deprecated, so use StorageReference.getDownloadUrl().
但是StorageReference.getDownloadUrl()返回Task,该任务必须异步处理,您不能执行Uri downloadUrl = photoRef.getDownloadUrl().getResult();
,否则您将获得java.lang.IllegalStateException: Task is not yet complete
But StorageReference.getDownloadUrl() returns Task, which must be handled asynchronously, you cannot do Uri downloadUrl = photoRef.getDownloadUrl().getResult();
else you will get java.lang.IllegalStateException: Task is not yet complete
因此,像这样异步处理
photoRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Uri downloadUrl = uri;
Toast.makeText(getBaseContext(), "Upload success! URL - " + downloadUrl.toString() , Toast.LENGTH_SHORT).show();
}
});
这篇关于错误:找不到类型为com.google.firebase.storage.UploadTask.TaskSnapshot的符号方法getDownloadUrl()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!