I'm trying to make a chatting app in which I want users to upload images, and I'm using Firebase RealTime Database to store user's data. taskSnapshot.downloadUrl() method is deprecated, as I've used a different approach to upload images to Firebase as shown in documentation
https://firebase.google.com/docs/storage/android/upload-files
and this StackOverflow
post:taskSnapshot.getDownloadUrl() is deprecated But still, image is not uploading to the database.
And I've also tried things like clean project, rebuild project, Invalidate and Restart.
This is the code I'm using to upload images to Firebase RealTime Database:
// ImagePickerButton shows an image picker to upload an image for a message mPhotoPickerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/jpeg"); intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); startActivityForResult(Intent.createChooser(intent, "Complete action using"), RC_PHOTO_PICKER); } }); and then in onActivityResults method :
@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { if (resultCode == RESULT_OK) { Toast.makeText(MainActivity.this, "Signed-In", Toast.LENGTH_SHORT).show(); } else if (resultCode == RESULT_CANCELED) { Toast.makeText(MainActivity.this, "Signed-In Cancel", Toast.LENGTH_SHORT).show(); finish(); } else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) { Uri selectedUri = data.getData(); final StorageReference storageReference = mChatPhotosStorageReference. child(selectedUri.getLastPathSegment()); UploadTask uploadTask = storageReference.putFile(selectedUri); Task<Uri> uriTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() { @Override public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return storageReference.getDownloadUrl(); } }).addOnCompleteListener(new OnCompleteListener<Uri>() { @Override public void onComplete(@NonNull Task<Uri> task) { if (task.isSuccessful()) { Uri downloadUrl = task.getResult(); FriendlyMessage message = new FriendlyMessage(null, mUsername, downloadUrl.toString()); mMessageDatabaseReference.push().setValue(message); } } }); This is the Github link for full project: https://github.com/harshabhadra/FriendlyChat