Ad

How To Get URI Of An Image From Datasnapshot

I am making an app where I can upload images to firebase then retrieve them and view them in a viewpager. The images have a name and an url. In addition to that, I want to be able to write the name of the image in a textbox and display the corresponding image in an imageview.

This is the code I'm working with :

    private void findImage(){

        final Query query = mDatabaseRef.orderByChild("name").equalTo(EditTextName.getText().toString());
        query.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.exists()) {
                    for (DataSnapshot NamedImage : dataSnapshot.getChildren()) {
 //i have tried this first but i don't know what method i should use to get the URI from the datasnapshot.
                          image.setImageURI(NamedImage.getValue());                   
 //then i have tried this but i can't use "context" here, nor can i apply .getImageUrl to the datasnapshot.
         Glide.with(context).load(NamedImage.getImageUrl()).into(image);
                }
            }
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}

I am new to android studio and java and I haven't studied it before starting this application. Any idea on what I should do please?

Ad

Answer

I found the solution to my problem :

private void findImage(){

    final Query query = mDatabaseRef.orderByChild("name").equalTo(EditTextName.getText().toString());
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                for (DataSnapshot NamedImage : dataSnapshot.getChildren()) {
                    SliderUtils sliderUtils = NamedImage.getValue(SliderUtils.class);
                    Glide.with(getApplicationContext()).load(sliderUtils.getImageUrl()).into(image);

                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
Ad
source: stackoverflow.com
Ad