0

getDownloadUrl() is not working with my project

StorageReference image_path = storageReference.child("profile_images").child(user_id + ".jpg");
                image_path.putFile(mainImageURI).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {

                        if(task.isSuccessful()){

                            Uri download_uri = task.getResult().getDownloadUrl();

                            Map<String, String> userMap = new HashMap<>();
                            userMap.put("name", user_name);
                            userMap.put("image", download_uri.toString());
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

1 Answers1

2

Try using this.

Task<Uri> task = taskSnapshot.getMetadata().getReference().getDownloadUrl();
 task.addOnSuccessListener(new OnSuccessListener<Uri>() {
     @Override
     public void onSuccess(Uri uri) {
         String photoLink = uri.toString();
     }
 });
Emil Mammadov
  • 380
  • 4
  • 20
  • Hi Emil and welcome to Stack Overflow! Please can you expand on your answer a little. Please explain how this code works, how it relates to the question and why it is a solution to the problem. – user230910 Jul 08 '19 at 21:36