To upload images to Firebase Storage I am attaching addOnSuccessListener
on the instance of the StorageReference. While overriding onSuccess
method I am calling getDownloadUrl()
on the instance of taskSnapshot
but it is giving me an error saying
Can't resolve method getDownloadUrl()
This app I had created 2 months ago, earlier this app was working fine and getDownloadUrl()
was working fine as well. Also, in taskSnapshot
instance when I press Ctrl+space, in the suggestions I don't find getDownloadUrl()
method. Why is it happening?
Code to onActivityResult()
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Signed in!!!1", Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Failed to sign in", Toast.LENGTH_SHORT).show();
finish();
}
}
else if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
Uri selectedPhoto = data.getData();
StorageReference localRefrence = storageReference.child(selectedPhoto.getLastPathSegment());
// Uploading the file on the storage
localRefrence.putFile(selectedPhoto).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FriendlyMessage message = new FriendlyMessage(mUsername, null, downloadUrl.toString());
databaseReference.push().setValue(message);
}
});
}
}