Uri resultUri = result.getUri();
String current_user_id= mCurrentUser.getUid();
StorageReference filepath = mImageStorage.child("profile_image").child(current_user_id+".jpg");
filepath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful()){
String download_url = task.getResult().getDownloadUrl().toString();
mUserDatabase.child("image").setValue(download_url).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
mProgressDialog.dismiss();
Toast.makeText(SettingsActivity.this,"Success upploading.",Toast.LENGTH_LONG).show();
}
}
});
}else {
Toast.makeText(SettingsActivity.this,"error on upploading.",Toast.LENGTH_LONG).show(); }
mProgressDialog.dismiss();
}
});
Asked
Active
Viewed 195 times
-6

InsaneCat
- 2,115
- 5
- 21
- 40

Raghad Hussien
- 15
- 1
- 4
-
2cannot resolve question. Please be clear – Tim Sep 03 '18 at 12:01
-
`getDownloadUrl` is no longer available on `task.getResult()`, but must now be called on `StorageReference filepath`. See the Firebase documentation here: https://firebase.google.com/docs/storage/android/upload-files#get_a_download_url or the simpler code here: https://stackoverflow.com/questions/51056397/how-to-use-getdownloadurl-in-recent-versions/51064689#51064689 – Frank van Puffelen Sep 03 '18 at 14:38
2 Answers
0
You must add addOnSuccessListener()
after getDownloadUrl()
then get the url string inside onSuccess()
method.

Tepits
- 374
- 6
- 19
0
Try this:
filepath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//Do what you need to do with the URL
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});

Alex Mamo
- 130,605
- 17
- 163
- 193