Muhammad Faisal Amin avatar

Firebase Cloud Storage | Android App Development | Lecture#59 | Hive Learners

faisalamin

Published: 29 Aug 2022 › Updated: 29 Aug 2022Firebase Cloud Storage | Android App Development | Lecture#59 | Hive Learners

Firebase Cloud Storage | Android App Development | Lecture#59 | Hive Learners

𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼

Dear Hive Learners, In the previous lecture we learn how to get the Profile Image in an Image View. Today we will configure the FirebaseStorage so that we can save this image in our Firebase storage when the user signup. We will save the link to the image in our real-time database. When we successfully upload an image to Firebase Storage we will get a link to access the image.

alt

GitHub Link

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

What Should I Learn

  • How to add Firebase Cloud Storage to our peoject

Assignment

  • Configure Firebase Cloud SDK to your project

Procedure

First of all, we need to open the Firebase Assistance. This will help us to implement the dependencies in one click. Open the Cloud Storage section and connect your app to Firebase and click on Add the Cloud storage SDK to your app. This will implement the dependencies and sync the project. Wait for the project to sync successfully.

alt

Click on Accept Changes.

alt

Now declare and initialize the Firebase Storage and the Storage Reference variables.

    private FirebaseStorage storage = FirebaseStorage.getInstance();
    private StorageReference storageRef = storage.getReference();

alt

Now we can use this storage reference to save the images in a child. Let's name it profile_images. We can implement the On Complete Listener and this time I am using null in place of File Uri as we do not pick the Uri yet.

 storageRef.child("profile_images").putFile(null).addOnCompleteListener(task -> {


        });

alt

We can show the Progressbar when the file is uploading and cancel if the task is failed or successful.

storageRef.child("profile_images").putFile(null).addOnCompleteListener(task -> {
            progressDialog.setMessage("Please wait...");
            progressDialog.show();
            progressDialog.setCancelable(false);

            if (task.isSuccessful()) {
                if (progressDialog.isShowing()) {
                    progressDialog.cancel();
                    Toast.makeText(this, "Uploaded", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
                if (progressDialog.isShowing()) {
                    progressDialog.cancel();
                }
            }


        });

alt

In the next lecture, we will create a function upload_image with the parameter Uril. This function will accept the Uri where is called. In the Activity result method, we will call save the Uri in a variable,, and on the profile creation time we can set the Uri in his function or we can use this Uri for the UserProfileChangeRequest.

hl_divider.png

Thank You

hl_footer_banner.png

Leave Firebase Cloud Storage | Android App Development | Lecture#59 | Hive Learners to:

Written by

Android | Python | Software Engineer

Read more #hive-153850 posts


Best Posts From Muhammad Faisal Amin

We have not curated any of faisalamin's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Muhammad Faisal Amin