0

Here is my image in firebase under the folder images/..

enter image description here

And i have create a model class which looks something like this

public class AdminNewItemModel {
    String name , dis , price , image;

    public AdminNewItemModel() {
    }

    public AdminNewItemModel(String name, String dis, String price, String image) {
        this.name = name;
        this.dis = dis;
        this.price = price;
        this.image = image;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDis() {
        return dis;
    }

    public void setDis(String dis) {
        this.dis = dis;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }
}

im able to get the other fields name price and etc like this

        for(DataSnapshot x : snapshot.getChildren()){
            AdminNewItemModel temp = x.getValue(AdminNewItemModel.class);
            list.add(temp);
        }

But i don't know how can i use the image name now to get the image.

I usually use this picasso to load the images but that thing requires url. Any suggestion please

Edit: this is how i upload the data first

public static void addNewFoodItem(String cardNo , String name , String dis , String price , Uri image , Context context){
    FirebaseStorage storage = FirebaseStorage.getInstance();
    StorageReference storageReference = storage.getReference();

    String imageId = UUID.randomUUID().toString();
    AdminNewItemModel data = new AdminNewItemModel(name , dis , price , imageId);
    firebaseDatabase.getReference().child("food items").child(cardNo).child(name).setValue(data);



    StorageReference temp = storageReference.child("images/" + imageId);

    temp.putFile(image).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            //Snackbar.make(context.findViewById(android.R.id.content) , "image uploaded" , Snackbar.LENGTH_LONG).show();
            Toast.makeText(context, "image uploaded", Toast.LENGTH_SHORT).show();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(context , "failll imageeeee" , Toast.LENGTH_SHORT).show();
        }
    });

}
Tehleel Mir
  • 743
  • 8
  • 27

0 Answers0