I am having a problem with my Android code. I am developing a game on Android. I first stored my images on resource file. But now I want to store them on Firebase. My plan was to download them using Picasso and add them to an Arraylist. But it doesnt have a method for returning just a drawable object. I tried to fetch BitMap and convert it to a drawable but it didnt work.
flagImages=new ArrayList<Drawable>();
flagImages.add(getResources().getDrawable(R.drawable.flag1));
flagImages.add(getResources().getDrawable(R.drawable.flag2));
flagImages.add(getResources().getDrawable(R.drawable.flag3));
I want to change the code above. Do you have any ideas? What should I use? My primary aim is to put the images into my ArrayList.
Step 1: Upload all your images into Firebase Storage
. Every image that is uploaded has a specific reference
which you'll be able to save in the Firebase Database
under a node named links
.
Step 2: Attach a listener
on the link
node and get all the reference of your images.
Step3: You will need this build dependency:
compile 'com.firebaseui:firebase-ui-storage:1.2.0'
compile 'com.firebaseui:firebase-ui-database:1.2.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
Step4: Load images from the Firebase
StorageReference
using Glide
instead of Picasso
.
Glide.with(MainActivity.this)
.using(new FirebaseImageLoader()) // <== ADD THIS
.load(storageReference)
.signature(new StringSignature(localFile.length() + "@" + localFile.lastModified()))
.into(images.get(i));
Step 5: Add your images into your ArrayList
.