Please check the code i am getting an error at getDownloadUrl() method. As it is not being accepted by the firebase. I am a beginner at this, so can anyone please suggest the changes i have to make in this code.
This snippet is basically focused on getting the image url from the storage and add it in the database section in firebase. But the getDownloadUrl is not working, please suggest the changes in the snippet to make it happen.
StorageReference filePath = userProfileImagesReference.child(currentUserID + ".jpg");
filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful())
{
Toast.makeText(SettingsActivity.this, "Profile Image Uploaded", Toast.LENGTH_SHORT).show();
//error here
final String downloadURL = task.getResult().getDownloadUrl().toString();
rootRef.child("Users").child(currentUserID).child("image")
.setValue(downloadURL)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful())
{
Toast.makeText(SettingsActivity.this, "Image Saved", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
String errorMSG = task.getException().toString();
Toast.makeText(SettingsActivity.this, "Error: "+errorMSG, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
else
{
String error = task.getException().toString();
Toast.makeText(SettingsActivity.this, "Error: "+error, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});