Upload and Retrieve Image from Firebase - Make Android App Similar to Whatsapp Android Studio

preview_player
Показать описание
In this video tutorial we will retrieve images from firebase in android. So in this video you will learn how to retrieve image from firebase storage android.
We will upload and retrieve image from firebase database in android studio for our android app like whatsapp in Android Studio using firebase database.

For new Updates and information you can Follow me on:
Рекомендации по теме
Комментарии
Автор


Importent Notice:
Make sure to check and compare your "AndroidManifext.xml" lines of code for "Intent Filter". Also do check the dependencies version.
If anyone is new to android development then please replace & use the same versions for the dependencies.

CodingCafe
Автор

So much useful tutorial series with good explanation.
Really you are a good teacher.

desirecode
Автор

Awesome have completed all 27 videos without one Error ....Really very nice.add notifications for group chat

TRK
Автор

Hey i got the solution of update button. Here i can see too many people are facing a problem.When someone is click on update button then photo get deleted.
Fix:
stem 1: make a global string variable.
like: private String photoUrl;
step 2: set into the private void RetrieveUserInfo();
step3: in update function just write profileMap.put("image", photoUrl);


Problem will be solved .(In Sha Allah)

hasanmahmud
Автор

Brother image is updated successful in database. But in imageview it doesn't display.even my imageview get invisible

HarshPatel-kyvk
Автор

hello brother, i am facing problem in this video part.
as i choose image and click crop than image is uploaded in firebase successfully but my imageview doesnot display image, not only image it totally invisible. though it invisble i can open gallery on clicking it but i cant display image.
i want to tell you in advance that i am working with api 30 and and my device os is 10.
also i replace getDownloadUrl() method to below:
because i cant access that older method.

please help me to solve that stuff.

HarshPatel-kyvk
Автор

but there is 1 error when i click on 'update' Button the image got removed..
how to fix this?
please help me
i m making this for 3rd yr project

soletune
Автор

Anybody having trouble retrieving image and displaying it, try this:


1. In gradle-app add this line : implementation


2. To retrieve image add this line:


3. For the image to be updated instantly.


if(task.isSuccessful()){
Toast.makeText(SettingsActivity.this, "Image saved in database successfully", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
/// add this line
}


I was stuck on this for 2 weeks and this solved it, Hope this helps!

nouraldinzeina
Автор

Those who have that Update button, when they click the update button the profile picture will be deleted, you should check the update method in your code once, in HashMap there is not two strings, one is String, and one is the Object, please change that, and the problem will be solved.
check the below code
HashMap<String, Object> profileMap = new HashMap<>();
profileMap.put("uid", currentUserID);
profileMap.put("name", username);
profileMap.put("status", status);

raminsultanzada
Автор

I saw many had problems with the image being deleted when you click update.
I had the same problem, the issue is that in the "updateSettings()" method the HashMap you upload to FireBase has no picture link.

The Way I solved that is by storing the downloadUrl from the "onActivityResult()" method into a global String and added it to the map if it is not empty.

Something like: declare global
private String photoUrl = " ";

and in the "onActivityResult()" after we get the uri, give the value of the uri to the photoUrl, like this:
final String downloadUrl = uri.toString();
photoUrl = downloadUrl;

then when you create the HashMap:

HashMap<String, String> profileMap = new HashMap<>();
profileMap.put("uid", currentUserID);
profileMap.put("name", setUserName);
profileMap.put("status", setUserStatus);
//check if there is a photo url to be uploaded

profileMap.put("image", photoUrl);
}


Hope this helps!

andreibichir
Автор

Those facing problem in retrieval Image Replace Your code to in if(result==RESULT_OK) to

if(resultCode == RESULT_OK)
{
loadingBar.setTitle("Set Profile Image");
Image Updatation in porgress");

loadingBar.show();
Uri resultUri = result.getUri();
final StorageReference filePath = + ".jpg");
uploadTask = filePath.putFile(resultUri);
Task<Uri>uriTask = Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
if (!task.isSuccessful()) {
throw task.getException();
}

// Continue with the task to get the download URL
return filePath.getDownloadUrl();
}
})
.addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override

if (task.isSuccessful()) {


final String downloadURL = task.getResult().toString();
String ImageUploadId = RoofRef.push().getKey();

// Adding image upload id s child element into databaseReference.


.setValue(downloadURL);
, "Data Successfully Uploaded", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
} else {
// Handle failures
// ...
loadingBar.dismiss();
, "Error While Uploaded", Toast.LENGTH_SHORT).show();
}

}
});


}

fadikhan
Автор

Hello, please my profile image has been saved alright in the firebase storage and databasse but can't display on the circular imageview. Can you help please? i'm really stack over there

AllForChristYouthMission
Автор

can someone share with me with full settings activity code?pls, I checked all comments but I still have a problem with a picture that I saved in firebase, I mean that when I save the picture it added to Firebase but didnt display on a screen .Thx

CoolGuyAlive
Автор


Not working, when I am tapping on crop circle imageview disappeared but I got the toast that image is saved successfully in database
Help me guys with this error?

SumitSingh-bdyb
Автор

For implementation
This is the solution : (Just copy & paste onActivityResult method )
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode==GalleryPick && resultCode==RESULT_OK && data!=null)
{
Uri ImageUri = data.getData();

CropImage.activity()

.setAspectRatio(1, 1)
.start(this);
}

if (requestCode ==
{
CropImage.ActivityResult result =

if (resultCode == RESULT_OK)
{
loadingBar.setTitle("Set Profile Image");
loadingBar.setMessage("Please wait, your profile image is updating...");

loadingBar.show();

Uri resultUri = result.getUri();


final StorageReference filePath = + ".jpg");

{
@Override
{
if (task.isSuccessful())
{
Toast.makeText(SettingsActivity.this, "Profile Image uploaded Successfully...", Toast.LENGTH_SHORT).show();


// final String downloaedUrl =

OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
final String downloaedUrl =uri.toString();


.setValue(downloaedUrl)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
{
if (task.isSuccessful())
{
Toast.makeText(SettingsActivity.this, "Image save in Database, Successfully...", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
String message =
Toast.makeText(SettingsActivity.this, "Error: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
// Handle any errors
}
});



}
else
{
String message =
Toast.makeText(SettingsActivity.this, "Error: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}

}

marouaneazza
Автор

@Mohammad Ali plz do the needful, how to display unread messages or count

DaljitSingh-tcwt
Автор

Hello everyone ! The image do not upload in database and do not show up on the imageView because of the firebase latest library . Use 11.0.4 ., with above coding your code will work .

SaraJavedAkhtar
Автор

If you have errors about getDownloadUrl()


see this solution:
Task<Uri> result =
OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String download_url = uri.toString();
}
});

ricard
Автор

if you have problem in firebase all firebase dependencies changed in 11.8.0

webkartstudio
Автор

mine is Suggesting i should use getUploadSessionUri so i used this code "getUploadSessionUri" but its not retrieving the photo from database help what can i do

balladsamu