Firebase存储OnSuccessListener无法正常工作

时间:2018-11-15 09:41:20

标签: android firebase firebase-storage

我想将图像上传到Firebase。为此,我正在使用Firebase Storage OnSuccessListener。但是OnSuccessListener无法正常工作。它显示:

  

无法解析符号“ OnSuccessListener”

 private void startPosting(){

    mProgess.setMessage("Uploading Quotes");
    mProgess.show();

    final String Quote_val = mPostQuote.getText().toString().trim();

    final String Author_val = mPostAuthor.getText().toString().trim();

    if (!TextUtils.isEmpty(Quote_val) && !TextUtils.isEmpty(Author_val) && mImageUri !=  null){

        StorageReference filepath = mStorage.child("Quote_Image").child(mImageUri.getLastPathSegment());

        filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                Uri downloadUrl = taskSnapshot.getDownloadUrl();
                DatabaseReference newPost = mDatbase.push();
                newPost.child("Quotes").setValue(Quote_val);

                newPost.child("Quote_Author").setValue(Author_val);
                newPost.child("Images").setValue(downloadUrl);
                mProgess.dismiss();

                startActivity(new Intent(adminUpdateQuotesSend.this, QuoteList.class));
            }
        });
    }
}

我正在使用:

implementation 'com.google.firebase:firebase-storage:9.2.0'

1 个答案:

答案 0 :(得分:0)

您可以使用CompletionListener:

filepath.putFile(mImageUri, new DatabaseReference.CompletionListener() {
  void onComplete(DatabaseError error, DatabaseReference ref) {
     if(error==null){
       //success
     }
  }
});