How to get the urls of all images stored in firebase in android?

I am doing this Android project in which I want to get help on retrieving all the URLs stored in the Firebase repository and displaying them all in imageview. The problem with this code is that it retrieves only one download URL. How can I get all the urls for all the images stored in Firebase. In short: there is one activity in which I save images in firebase, and in others I want to get all the images in Imageview. How can i do this? Thanks

if(requestCode== GALLERY_INTENT && resultCode== RESULT_OK)
    {
          mProgress.setMessage("Uploading....");
          mProgress.show();
          Uri uri =data.getData();
        StorageReference filepath = mStorage.child("Photos").child(uri.getLastPathSegment());
        filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                mProgress.dismiss();
                Uri downloadUri = taskSnapshot.getDownloadUrl();

                Picasso.with(MainActivity.this).load(downloadUri).fit().centerCrop().into(mImageView);
                Toast.makeText(MainActivity.this,"Upload done",Toast.LENGTH_LONG).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(MainActivity.this,"Upload  failed",Toast.LENGTH_LONG).show();
            }
        });
    }
+4
source share
2 answers

, API , firebase. , , , URL- .. .

, , .

:

.

UploadTask uploadTask = storageRef.putBytes(data,storageMetadata);
    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {

        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
             //Save to database using
         //taskSnapshot.getMetadata().getCustomMetadata(StringKeys.SOME_KEY);
        }
    }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

        }
    });
+2

Firebase API, Firebase Storage. : , Firebase Storage, getDownloadUrl(); .


DatabaseReference:

private DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();

, java, :

public class Image implements Serializable {
    public String downloadUrl;

    public Image() {
    }

    public Image(String dUrl) {
        this.downloadUrl = dUrl;
    }
}

java- onSuccess(UploadTask.TaskSnapshot taskSnapshot):

Uri downloadUri = taskSnapshot.getDownloadUrl();
Image image = new Image(downloadUri.toString());
String userId = databaseReference.push().getKey();
databaseReference.child(userId).setValue(image);

. , Firebase Storage, :

private ArrayList<Data> list;
...
private void getImagesList() {
    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
                Data data = new Data(childSnapshot.child("downloadUrl").getValue().toString());
                list.add(data);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
0

Source: https://habr.com/ru/post/1677510/


All Articles