How to download files Firebase to Android device

Hello Android lovers, In here I am going to discuss “How to download files firebase to Android device“. That means we are going to add a download button to your android application and when it click your file will download to your device.

How to download files Firebase to Android device

First of all in your android xml file, create a design to load the image and a button to download. Like this.



           android:text= "Download"


In this xml file, image will display and fetch on the ImageView. Lets create the Java file.

In your Java file, first add properties.

private ImageView img01,
private Button btnDownload;

Then define in the onCreate() method.

img01 = findViewById(;
btnDownload = findViewById( );

We are going to develop download option when the button click. So we have to implement the setOnClickListener method.

#Step 02 setOnClickListener method – How to download files Firebase to Android device

We have to implement in the onClick() method. In here I am going to create another method download option. So follow the below code to get an idea about how to implement.

public void downloadFile(Context context, String fileName, String fileExtension, String destinatioinDirectory, String url){

        DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        Uri uri = Uri.parse(url);
        DownloadManager.Request request = new DownloadManager.Request(uri);




After that I am going to add that method to the setOnClickListener. Like this.

 btnDownload .setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                storageReference = firebaseStorage.getInstance().getReferenceFromUrl("gs://").child("m3.jpg");
                storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    public void onSuccess(Uri uri) {
                        String url = uri.toString();
                        downloadFile(ImagesActivity.this,"m3", ".jpg","AndroidTest" , url );

Let me explain this method.

  • In my Firebase storage, I have a image called m3.jpg.
  • Toast means, it is a Toast message when displaying when downloading the file.
  • StorageReference is for set the Firebase instance URL to get the image. You can see getReferenceFromUrl() method is here to set the URL and for the child() method, we are going to add the image name and the format.
  • storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() this is the method. We are implementing the code in the onSuccess method.
  • After that we are passing attributes to the downloadFile() method.

Fetch Image to ImageView – #Step 03 in How to download files Firebase to Android device

Create another method to implement the fetch image option.

  private void loadImage(){

        storageReference = firebaseStorage.getInstance().getReferenceFromUrl("gs://").child("copy.jpg");
        try {
            final File locaFile = File.createTempFile("image", "jpg");
            storageReference.getFile(locaFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                    Bitmap bitmap = BitmapFactory.decodeFile(locaFile.getAbsolutePath());
        } catch (IOException e) {


In the onSuccess() method we are going to set the file to Bitmap.

After that you can run the app and you can see the output.

Thank you. Make sure to leave a comment.

If you are a newbie to Android. Follow and refer articles. Click below link to get started.

Other articles from different categories.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x