Until now, the way to get the url from file on Storage in Firebase, I used to do this
taskSnapshot.getDownloadUrl, but nowadays is deprecated, which method I
Just use a Task instead of ref.putFile(uriImage) .addOnSuccessListener(new OnSuccessListener() Nowadays, firebase references suggest using Uploadtask objects
I've done it like this:
UploadTask uploadTask;
uploadTask = storageReferenceProfilePic.putFile(uriProfileImage );
Task urlTask = uploadTask.continueWithTask(new Continuation>() {
@Override
public Task then(@NonNull Task task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
// Continue with the task to get the download URL
return storageReferenceProfilePic.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (task.isSuccessful()) {
progressBarImageUploading.setVisibility(View.GONE);
Uri downloadUri = task.getResult();
profileImageUrl = downloadUri.toString();
ins.setText(profileImageUrl);
} else {
// Handle failures
// ...
}
}
});
Notice these lines in the above code:
Uri downloadUri = task.getResult();
profileImageUrl = downloadUri.toString();
Now profileImageUrl contains something like "http://adressofimage" which is the url to acess the image
Now you're free to use the String profileImageUrl however you wish. For e.g., load the url into an ImageView using Glide or Fresco libraries.