There's a mistake in this code:
String download_url=task.getResult.getStorage.getDownloadUrl.toString);
When I run the program, I choose a picture from the gallery and I post it, and I get a message:
User is not authenticated, please authenticate using Firebase Authentication and try again
final StorageReference newPhoto=mPhotosStrorage.child(imageUri.getLastPathSegment());
newPhoto.putFile(imageUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful())
{
final String myKey=mPhotosDatabase.push().getKey();
//this error String download_url=task.getResult().getDownloadUrl().toString();
String datem=getDateTime();
DatabaseReference newDatabase=mPhotosDatabase.child(myKey);
newDatabase.child("postid").setValue(myKey);
newDatabase.child("postedby").setValue(userId);
newDatabase.child("postedon").setValue(datem);
newDatabase.child("postdetails").setValue(post);
newDatabase.child("postlikes");
newDatabase.child("postviews");
newDatabase.child("postcomments");
newDatabase.child("postimage").setValue(download_url).addOnCompleteListener(new OnCompleteListener<Void>() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
pb.setVisibility(View.GONE);
Pair[] pairs=new Pair[1];
pairs[0]=new Pair<View,String>(homeLayout,"etTransition");
ActivityOptions options=ActivityOptions.makeSceneTransitionAnimation(PostActivity.this,pairs);
startActivity(new Intent(PostActivity.this,HomeActivity.class),options.toBundle());
}
}
});
}else {
Toast.makeText(PostActivity.this, "Error:"+task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
Please help solve it and rewrite the code for me.