Android Java – .getDownloadUrl().toString() in Firebase returns "com.google.android.gms.tasks.zzu@9501820 " how to use this to load the image?

huangapple go评论67阅读模式
英文:

Android Java - .getDownloadUrl().toString() in Firebase returns "com.google.android.gms.tasks.zzu@9501820 " how to use this to load the image?

问题

我正在使用Firebase进行安卓项目开发,用于数据库管理,但是我无法检索已上传的图片,因为无法获取我所使用图片的URL。我尝试使用.getDownloadUrl()方法,但它没有返回URL,而是返回了com.google.android.gms.tasks.zzu@9501820。

英文:

I am working on an android project using firebase for database but i am not able to retrieve the uploaded image as i can't get the url for the image i used .getDownloadUrl() method but it doesn't return the url but com.google.android.gms.tasks.zzu@9501820.

答案1

得分: 3

你需要在getDownloadUrl()上注册一个回调,就像下面这样,因为它是Task的实例,而不是StringTask是异步的,你不能只是使用toString()来获取URL。

dateRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>(){
    @Override
    public void onSuccess(Uri downloadUrl) {                
       // 对下载URL做一些操作
    } 
});
英文:

You will have to register a callback on getDownloadUrl() like below because it is an instance of Task, not String. Task is asynchronous, you can't just do toString() to get an url.

dateRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;(){
        @Override
        public void onSuccess(Uri downloadUrl) {                
           //do something with downloadurl
        } 
    });

huangapple
  • 本文由 发表于 2020年4月10日 19:27:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/61139320.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定