如何从Firebase数据存储中获取图片网址?

时间:2018-08-14 22:05:41

标签: android firebase firebase-realtime-database firebase-storage

我在下面使用此代码,我得到的代替URL的只是com.google.android.gms.tasks.zzu@a0a540。如何获取实际的网址?

 filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
        if(task.isSuccessful()){
            mImageStorage.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
               @Override
               public void onSuccess(Uri uri) {

                   Uri downloadUri = filePath.getMetadata().getDownloadUrl();
                   generatedFilePath = downloadUri.toString();
                    String downlaodURL = uri.toString();

                    (mUserDatabase.child("image").setValue(downlaodURL).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if(task.isSuccessful()){
                            mUploadImage.dismiss();
                            Toast.makeText(SettingsActivity.this,"image uploaded",Toast.LENGTH_SHORT).show();
                        }
                        else{
                            Toast.makeText(SettingsActivity.this,"image URL not set",Toast.LENGTH_SHORT).show();
                        }
                    }
                });
               }
           });
        }
        else{
            mUploadImage.hide();
            Toast.makeText(SettingsActivity.this,"Error uploading image",Toast.LENGTH_SHORT).show();
        }
    }
});

0 个答案:

没有答案