Retrieve Image from Firebase Storage in Android
Coding Tutorials

Retrieve Image from Firebase Storage in Android

Vidhi Markhedkar
In this Tutorial, we will learn how to retrieve image from firebase storage in Android Studio.  We have already shown you how to do Google Firebase authentication you can check the Firebase Tutorial. So lets start this Firebase Storage.

Firebase

Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011, then acquired by Google in 2014. As of October 2018, the Firebase platform has 18 products, which are used by 1.5 million apps. It helps us to quickly develop high-quality apps, grow our user base, and earn more money.

GLIDE

Glide is an Image Loader Library for Android developed by bump tech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application. Glide supports fetching, decoding, and displaying video stills, images, and animated GIFs.

LET'S CONFIGURE FIREBASE TO YOUR ANDROID PROJECT

1. Open  firebase.google.com.

2. Click on "Get Started project".

3. Click on "Add Project".

4. Add Project Name of your choice.

Firebase Image Create

5. Click on the "Create Project" Button at the bottom.

6. Click on Android symbol.

Firebase-image

7. You will see a page titled "Add Firebase to your Android app"

Image from Firebase 1

8. Add your Android package name.

For example  ->   com.example.retrieving_images_from_firebase;

9. Add SHA1 key and click on "Register App".

10. Click on "Download google-services.json" button to download this file.

11. Then, add google-services.json inside your project/app folder.

Retrieve Image 3

12. Open your Project’s gradle(Project)file. Add this dependency inside dependencies block.

classpath "com.google.gms:google-services:3.0.0"

Below is a screenshot of the same:-

Android Dependencies Retrieve Image 4

13. Open your project’s gradle(Module:app)file. Add dependencies:-

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.picasso:picasso:2.71828'
testImplementation 'junit:junit:4.12'
implementation 'com.github.bumptech.glide:glide:4.7.1'
compile 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.google.firebase:firebase-database:11.0.2' 
compile 'com.google.firebase:firebase-storage:11.0.2' 
compile 'com.google.firebase:firebase-auth:11.0.2' 
compile 'com.firebaseui:firebase-ui-database:2.1.0' 

Below is a screenshot of the same:-

dependencies Retrieve Image 5

14. Now finally add below packagingOptions just bottom of buildTypes block.

packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }

Below is a screenshot of the same:-

Retrieve Image 6

15. Open firebase.google.com, Select your project.

Now click on Database -> Rules. Add the following lines:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

Click on Storage -> Rules. Add the following lines:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

16. Now Click on Storage->Files. Upload an image using the "Upload file" button.

Firebase storage Retrieve Image 7

17. Click on any uploaded image. Then on the right-hand side, at the bottom, you will find Download URL1. Copy that location.

firebase Retrieve Image 8

Activity_main.xml

Create an Imageview to retrieve an image of a given URL.




    

    


MainActivity.java

package com.example.retrieving_images_from_firebase;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

public class MainActivity extends AppCompatActivity {

    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView=findViewById(R.id.image);

        String url="https://firebasestorage.googleapis.com/v0/b/retrieve-images-958e5.appspot.com/o/9.PNG?alt=media&token=6bd05383-0070-4c26-99cb-dcb17a23f7eb";//Retrieved url as mentioned above

        Glide.with(getApplicationContext()).load(url).into(imageView);

    }
}

Congratulations!! Now, You are in a position to run your application.

After running your application, you will find your retrieved image.

Image from Firebase

You can access code through our GitHub link also:-

DOWNLOAD FROM GITHUB

This was a simple tutorial based on Firebase Storage Image Retrieval. Comment down below for any query.

Stay tuned for more such Android articles!!!!!!!

Vidhi Markhedkar's profile picture

Vidhi Markhedkar

Android developer and writer with a passion for creating innovative and user-friendly apps.

Related Posts

7 Top Samsung Galaxy Ring Alternatives for 2025

7 Top Samsung Galaxy Ring Alternatives for 2025

Tired of waiting for the Samsung Galaxy Ring to hit the market? You’re not alone. While the buzz around Samsung’s smart ring continues, a plethora of impressive alternatives is already available. These devices deliver advanced health tracking, stylish designs, and unique features that cater to various lifestyles. The current lineup of smart rings caters to […]

What Is Quiet Mode on Instagram and How to Activate It

What Is Quiet Mode on Instagram and How to Activate It

Ever wondered what Quiet Mode on Instagram is all about? This simple yet powerful Instagram feature helps you take a break from the constant buzz of notifications and focus on what truly matters. Whether you’re striving for better work-life balance, dedicating time to studying, or simply trying to disconnect from social media distractions, Quiet Mode […]

How to Make a Bed in Minecraft (Step-by-Step Guide)

How to Make a Bed in Minecraft (Step-by-Step Guide)

A bed in Minecraft is very important. It lets you skip the night and set your spawn point, so if you die, you will return to your bed instead of the original world spawn. This guide will show you how to gather materials, craft a bed, and set your spawn point. We’ll also show you how to customize your bed, build bunk […]

10 Best MMORPG Games For Android

10 Best MMORPG Games For Android

Not too long ago, MMORPG games and powerful gaming consoles were mostly exclusive to PCs. They required high-end graphics and systems to deliver their immersive gameplay. But times have changed. With the rise of gaming-oriented smartphones, you can now enjoy PC-like gaming experiences on your Android device. Thanks to these technological advancements and faster internet […]

Roblox: Fruit Battlegrounds codes (January 2025)

Roblox: Fruit Battlegrounds codes (January 2025)

Fruit Battlegrounds codes are all about getting more gems and help you to shoot up your rank in this One Piece anime-inspired game. This Fruit Battlegrounds was made by Popo developer. It is an action-packed game where players battle it out using unique fruit-based abilities. With constant updates, new fruits, and exciting challenges, it’s a fruity frenzy you won’t […]

Roblox: Ultimate Football Codes (January 2025)

Roblox: Ultimate Football Codes (January 2025)

Want to get some extra items for Ultimate Football in Roblox? You’ve come to the right place! Here’s the latest list of codes to help you score touchdowns and look stylish on the field. These codes offer free rewards such as coins and cosmetics to enhance your gameplay. What are Ultimate Football Codes? Ultimate Football […]

Roblox: Da Hood Codes (January 2025)

Roblox: Da Hood Codes (January 2025)

Are you a fan of Roblox games, in this article we will look at the Roblox Da Hood Codes for December 2024 that will help you unlock exclusive items, improve your gameplay and dominate the streets of Da Hood. You can feel that the game is inspired by the Grand Theft Auto series and there […]