Last active
October 5, 2021 05:47
-
-
Save jonathanbcsouza/13929ab81077645f1033bf9ce45beaab to your computer and use it in GitHub Desktop.
SOLUTION FOR: DEPRECATED >> Uri downloadUrl = taskSnapshot.getDownloadUrl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Udacity - Does not working | |
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == RC_SIGN_IN) { | |
if (resultCode == RESULT_OK) { | |
Toast.makeText(getContext(), "Signed in!", Toast.LENGTH_SHORT).show(); | |
} else if (resultCode == RESULT_CANCELED) { | |
Toast.makeText(getContext(), "Sign in canceled", Toast.LENGTH_SHORT).show(); | |
getActivity().finish(); | |
} else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) { | |
Uri selectedImageUri = data.getData(); | |
// Get a reference to store file at chat_photos/<FILENAME> | |
StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment()); | |
mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment()); | |
// Upload file to Firebase Storage | |
photoRef.putFile(selectedImageUri) | |
.addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { | |
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { | |
// When the image has successfully uploaded, we get its download URL | |
Uri downloadUrl = taskSnapshot.getDownloadUrl(); | |
// Set the download URL to the message box, so that the user can send it to the database | |
ChatMessageClass friendlyMessage = new ChatMessageClass(null, mUsername, downloadUrl.toString()); | |
mMessagesDatabaseReference.push().setValue(friendlyMessage); | |
} | |
}); | |
} | |
} | |
} | |
// ------------------------------------------------------------------------------------------------------------------------------------ | |
//Update - SOLUTION | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == RC_SIGN_IN && resultCode == RESULT_OK) { | |
Toast.makeText(this, "Signed in!", Toast.LENGTH_SHORT).show(); | |
} else if (resultCode == RESULT_CANCELED) { | |
Toast.makeText(this, "Sign in canceled!", Toast.LENGTH_SHORT).show(); | |
} else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) { | |
Uri selectedImageUri = data.getData(); | |
// Get a reference to store file at chat_photos/<FILENAME> | |
final StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment()); | |
photoRef.putFile(selectedImageUri) | |
.addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { | |
@Override | |
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { | |
//When the image has successfully uploaded, get its download URL | |
photoRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() { | |
@Override | |
public void onSuccess(Uri uri) { | |
Uri dlUri = uri; | |
FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, dlUri.toString()); | |
mMessagesDatabaseReference.push().setValue(friendlyMessage); | |
} | |
}); | |
} | |
}); | |
} | |
} |
Thanks man
thank you man
THANKS A LOT MAYN!!!!!! FINALLLLLYYYYYY WORKING. YOU ARE THE BEST PERSON ALIVE😭😭😭😭💖💖
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muchas gracias!!!