skip to Main Content

I am using firebase storage for saving images, when I retrieve them on application, files are not sorting alphabetically.
Firebase sorting files by date time, first upload showing on first then second.
I have a lot of files and cannot upload these files one by one.
Is there any way to sort files by alphabetically.
like

001.png
002.png
003.png
004.png
005.png

`

private void saveAllSigns() {
    showDialog();
    for (int i = 0; i < SignNameList.length; i++) {
        StorageReference storageReference = FirebaseStorage.getInstance().getReference().child(SignNameList[i]);
        int finalI1 = i;
        storageReference.listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
            @Override
            public void onSuccess(ListResult listResult) {
                List<StorageReference> list = listResult.getItems();
                for (StorageReference str : list) {
                    long SIZE = 1024 * 1024;
                    str.getBytes(SIZE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
                        @Override
                        public void onSuccess(byte[] bytes) {
                            saveData(bytes, str.getName(), finalI1);
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.d("SlashLog", "Firebase Exception: " + e.getMessage());

                        }

`

looking for solution

2

Answers


  1. Chosen as BEST ANSWER

    thanks for answer but error has resolved from here in data base helper ORDER BY ASC

            Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_SIGNS +" ORDER BY fileName ASC", null);
    

  2. According to the Firebase documentation given by frank, listAll() call should be returning the files in lexicographical order.

    Seems order of the files in the list is being changed by the for loop that iterates through the list. Maybe you should try sorting the list before iterating through it.

    listAll() method is being called inside a for loop that iterates over the SignNameList. If the elements in the SignNameList array are in chronological order, then the listAll() method will return the files in chronological order as well.

    As also mentioned here, Consistency of the result is not guaranteed if objects are inserted or removed while this operation is executing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search