listAll() does not work for firebase in Android

Tags: , , ,



i have created a function to list all files with in a reference.mStorageRef is defined public.

 public void ListFiles()
    {
        Log.d("FETCHING_DATA_STATUS","STARTED");
        mStorageRef = FirebaseStorage.getInstance().getReference("ImageFolder");

      
        mStorageRef.listAll()
                .addOnSuccessListener(new OnSuccessListener<ListResult>() {
                    @Override
                    public void onSuccess(ListResult listResult) {
                        for (StorageReference prefix : listResult.getPrefixes()) {
                          
                            Log.d("Storage_Prefix :",prefix.getName());
                        }

                       /* for (StorageReference item : listResult.getItems()) {
                           

                        }*/
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                 
                        Log.d("FETCHING_DATA_STATUS","Failed due to"+e.getMessage());
                    }
                }).addOnCompleteListener(new OnCompleteListener<ListResult>() {
            @Override
            public void onComplete(@NonNull Task<ListResult> task) {
                if(task.isSuccessful()) {
                    Log.d("FETCHING_DATA_STATUS", "FINISHED");
                }
            }
        });

    }

but when i execute this i get following ouput:

D/FETCHING_DATA_STATUS: STARTED
W/StorageUtil: no auth token for request
W/NetworkRequest: no auth token for request
D/FETCHING_DATA_STATUS: FINISHED
W/example.larn: Checksum mismatch for dex base.apk!classes2.dex
    Could not merge the profile. Clearing the profile data.

how can i use list all correctly.Please help

Answer

You’re looping over listResult.getPrefixes(), which are the subfolders in your ImageFolder.

Since you indicate you want to list files, you should loop over listResult.getItems() instead.

I find keeping the reference documentation open key to quickly fixing this sort of common mistake.



Source: stackoverflow