0

Heyho,

currently im working on my Firebase Database (android sdk). I managed to upload the image to the storage and save the url in my database (under the user ID).

Now im really out of ideas how to display the image from the database into a imageView. Probably you already understand that im trying create some type of "profile picture".

Btw. is would be really nice if someone can help me without using Glide. If Glide is needed i will get Glide then instead.

Thank you all for reading my question and helping me!

Database Image

prAcid
  • 3
  • 1
  • 1

1 Answers1

0

Firstly you can put an image using an url by using:

InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");

If you use the Firebase storage why don't you just download the file directly from there?

StorageReference mStorageRef = FirebaseStorage.getInstance().getReference();

StorageReference riversRef = mStorageRef.child("images/name.jpg");

File localFile = null;
try {
    localFile = File.createTempFile("images", "jpg");
} catch(IOException e) {
    e.printStackTrace();
}
riversRef.getFile(localFile)
        .addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                // Successfully downloaded data to local file
                // ...
            }
        }).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle failed download
        // ...
    }
});

If you do need to use the url then you will need to use an AsyncTask to get the image.