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

getDownloadUrl #48

Closed ggichure closed 5 years ago

ggichure commented 6 years ago

here is my code i have tried different code from stackoverflow nothing works for me.cant seem to fix the error Uri firebaseUrl = taskSnapshot.getDownloadUrl();

uploadTask.addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Uri firebaseUrl = taskSnapshot.getDownloadUrl();

                Toast.makeText(mContext, "photo upload success", Toast.LENGTH_SHORT).show();

                //insert into 'user_account_settings' node
                setProfilePhoto(firebaseUrl.toString());
Njuacha commented 6 years ago

Hello, I had a similar issue like you I just found out the method taskSnapshot.getDownloadUrl() is deprecated. So going back to the firebase documentation I found this code to achieve the same purpose

`uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task>() { @Override public Task then(@NonNull Task task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); }

                // Continue with the task to get the download URL
                return photoRef.getDownloadUrl();
            }
        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
            @Override
            public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
           // IT IS HERE THAT YOU CAN GET THE DOWNLOADABLE URL 
                    Uri downloadUri = task.getResult();
                    firebaseUrl = downloadUri;
           //TRY CALLING YOUR "setProfilePhoto" METHOD HERE LIKE BELOW
                   setProfilePhoto(firebaseUrl.toString());
                } else {
                    // Handle failures
                    // ...
                }
            }
        });`