udacity / and-nd-firebase

Course code repository for Firebase in a Weekend by Google: Android
https://www.udacity.com/course/firebase-in-a-weekend-by-google-android--ud0352
Apache License 2.0
299 stars 714 forks source link

taskSnapshot.getDownloadUrl() doesn't exist. #47

Open hamidsn opened 6 years ago

hamidsn commented 6 years ago

https://github.com/udacity/and-nd-firebase/blob/a8b875ac763f0b2d845154b5faace9e685d2326f/app/src/main/java/com/google/firebase/udacity/friendlychat/MainActivity.java#L202

I believe solution is @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Task urlTask = taskSnapshot.getStorage().getDownloadUrl(); while (!urlTask.isSuccessful()); Uri downloadUrl = urlTask.getResult(); //rest }

Deepan27 commented 6 years ago

try this bro

photoRef.putFile(selectedImageUri).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task>() { @Override public Task then(@NonNull Task task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return photoRef.getDownloadUrl(); } }).addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { Uri downloadUri = task.getResult(); FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUri.toString()); mMessageDatabaseReference.push().setValue(friendlyMessage); } else { Toast.makeText(MainActivity.this, "upload failed: " + task.getException().getMessage(), Toast.LENGTH_SHORT).show(); } } });