Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

android - How to return a boolean value when a file is successfully uploaded inside onSuccessListener?

First look at this. I call a function uploadUserPdf() inside submitProfile()

public void submitProfile() {
     if(!uploadUserPdf()) {
          return;
     }
     else {
        //...............
     }
}

And Here is the uploadUserPdf() function

private boolean uploadUserBiodataPdf() {
        Uri fileUri = Uri.parse(Pdf);
        final StorageReference storageReference = FirebaseStorage.getInstance().getReference().child("Pictures");
        StorageReference pdfRef = storageReference.child(mUser.getUid()).child(fileUri.getLastPathSegment());

        pdfRef.putFile(fileUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                pdfRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        Pdf = uri.toString();
                        Toast.makeText(ContinueProfile.this, "Pdf Uploaded", Toast.LENGTH_LONG).show();
                    }
                });
            }
        });
        return false;
    }

I want to return true if file is successfully uploaded. But I cannot find any space to write return true. Is it possible to return the true value if file is successfully uploaded ??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...