taskSnapshot.getDownloadUrl() method not working











up vote
2
down vote

favorite
1












private void uploadImageToFirebaseStorage() {
StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");

if (uriProfileImage != null) {
progressBar.setVisibility(View.VISIBLE);
profileImageRef.putFile(uriProfileImage)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.GONE);
profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressBar.setVisibility(View.GONE);
Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}


taskSnapshot.getDownloadUrl() method not working comes up with red line under it










share|improve this question




























    up vote
    2
    down vote

    favorite
    1












    private void uploadImageToFirebaseStorage() {
    StorageReference profileImageRef =
    FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");

    if (uriProfileImage != null) {
    progressBar.setVisibility(View.VISIBLE);
    profileImageRef.putFile(uriProfileImage)
    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
    progressBar.setVisibility(View.GONE);
    profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
    }
    })
    .addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
    progressBar.setVisibility(View.GONE);
    Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
    });
    }
    }


    taskSnapshot.getDownloadUrl() method not working comes up with red line under it










    share|improve this question


























      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      private void uploadImageToFirebaseStorage() {
      StorageReference profileImageRef =
      FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");

      if (uriProfileImage != null) {
      progressBar.setVisibility(View.VISIBLE);
      profileImageRef.putFile(uriProfileImage)
      .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
      @Override
      public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
      progressBar.setVisibility(View.GONE);
      profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
      }
      })
      .addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception e) {
      progressBar.setVisibility(View.GONE);
      Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
      }
      });
      }
      }


      taskSnapshot.getDownloadUrl() method not working comes up with red line under it










      share|improve this question















      private void uploadImageToFirebaseStorage() {
      StorageReference profileImageRef =
      FirebaseStorage.getInstance().getReference("profilepics/" + System.currentTimeMillis() + ".jpg");

      if (uriProfileImage != null) {
      progressBar.setVisibility(View.VISIBLE);
      profileImageRef.putFile(uriProfileImage)
      .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
      @Override
      public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
      progressBar.setVisibility(View.GONE);
      profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();
      }
      })
      .addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception e) {
      progressBar.setVisibility(View.GONE);
      Toast.makeText(ProfileActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
      }
      });
      }
      }


      taskSnapshot.getDownloadUrl() method not working comes up with red line under it







      android






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 29 at 13:52









      Adeel

      2,06961424




      2,06961424










      asked May 29 at 13:13









      David G

      5518




      5518
























          9 Answers
          9






          active

          oldest

          votes

















          up vote
          19
          down vote



          accepted










          in Firebase Storage API version 16.0.1.
          The getDownloadUrl() method using taskSnapshot object has changed.
          now you can use'
          taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
          to get download url from the firebase storage.






          share|improve this answer





















          • Thank you!.....
            – David G
            Jun 18 at 10:33


















          up vote
          2
          down vote













          My Google Firebase Plugins in build.gradle(Module: app):



          implementation 'com.firebaseui:firebase-ui-database:3.3.1'
          implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
          implementation 'com.google.firebase:firebase-core:16.0.0'
          implementation 'com.google.firebase:firebase-database:16.0.1'
          implementation 'com.google.firebase:firebase-auth:16.0.1'
          implementation 'com.google.firebase:firebase-storage:16.0.1'


          build.gradle(Project):



           classpath 'com.google.gms:google-services:3.2.1'


          My upload() function and fetching uploaded data from Firebase storage :



          private void upload() {
          if (filePath!=null) {
          final ProgressDialog progressDialog = new ProgressDialog(this);
          progressDialog.setTitle("Uploading...");
          progressDialog.show();

          final StorageReference ref = storageReference.child(new StringBuilder("images/").append(UUID.randomUUID().toString()).toString());
          uploadTask = ref.putFile(filePath);

          Task<Uri> urlTask = 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 ref.getDownloadUrl();
          }
          }).addOnCompleteListener(new OnCompleteListener<Uri>() {
          @Override
          public void onComplete(@NonNull Task<Uri> task) {
          if (task.isSuccessful()) {
          Uri downloadUri = task.getResult();
          progressDialog.dismiss();
          // Continue with the task to get the download URL
          saveUrlToCategory(downloadUri.toString(),categoryIdSelect);
          } else {
          Toast.makeText(UploadWallpaper.this, "Fail UPLOAD", Toast.LENGTH_SHORT).show();
          }
          }
          }).addOnSuccessListener(new OnSuccessListener<Uri>() {
          @Override
          public void onSuccess(Uri uri) {
          progressDialog.setMessage("Uploaded: ");
          }
          }).addOnFailureListener(new OnFailureListener() {
          @Override
          public void onFailure(@NonNull Exception e) {
          progressDialog.dismiss();
          Toast.makeText(UploadWallpaper.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
          }
          });
          }
          }


          FOR THOSE WHO ARE USING LATEST FIREBASE VERSION taskSnapshot.getDownloadUrl() method is DEPRECATED or OBSOLETE !!






          share|improve this answer




























            up vote
            2
            down vote













            Try Using this it will download the image from FireBase storage



            FireBase Libraries versions 16.0.1



            Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
            result.addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
            String photoStringLink = uri.toString();
            }
            });





            share|improve this answer





















            • Mark this as a valid ans
              – Pandiri Deepak
              Sep 15 at 9:53


















            up vote
            1
            down vote













            taskSnapshot.**getDownloadUrl**().toString(); //deprecated and removed


            use below code for downloading Url



             StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +` abc_10123 + ".jpg");

            profileImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
            {
            @Override
            public void onSuccess(Uri downloadUrl)
            {
            //do something with downloadurl
            }
            });





            share|improve this answer





















            • yes. it needs to be made final. please mark as solution if it helps you
              – Muhammad Saad
              May 30 at 9:37










            • final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
              – Muhammad Saad
              May 30 at 9:40










            • not all heroes wear capes
              – martinseal1987
              Jun 7 at 19:42


















            up vote
            0
            down vote













            for latest version try



            profileImageUrl = taskSnapshot.getStorage().getDownloadUrl().toString();





            share|improve this answer




























              up vote
              0
              down vote













              Try using this:



              taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()





              share|improve this answer






























                up vote
                0
                down vote













                You wont get the download url of image now using



                profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();


                this method is deprecated.



                Instead you can use the below method



                    uniqueId = UUID.randomUUID().toString();
                ur_firebase_reference = storageReference.child("user_photos/" + uniqueId);

                Uri file = Uri.fromFile(new File(mphotofile.getAbsolutePath()));
                UploadTask uploadTask = ur_firebase_reference.putFile(file);

                Task<Uri> urlTask = 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();
                }

                // Continue with the task to get the download URL
                return ur_firebase_reference.getDownloadUrl();
                }
                }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                @Override
                public void onComplete(@NonNull Task<Uri> task) {
                if (task.isSuccessful()) {
                Uri downloadUri = task.getResult();
                System.out.println("Upload " + downloadUri);
                Toast.makeText(mActivity, "Successfully uploaded", Toast.LENGTH_SHORT).show();
                if (downloadUri != null) {

                String photoStringLink = downloadUri.toString(); //YOU WILL GET THE DOWNLOAD URL HERE !!!!
                System.out.println("Upload " + photoStringLink);

                }

                } else {
                // Handle failures
                // ...
                }
                }
                });





                share|improve this answer




























                  up vote
                  0
                  down vote













                  I still having this error. What might be wrong? I already changed the permissions, and users to anonymous.



                  enter image description here






                  share|improve this answer




























                    up vote
                    0
                    down vote













                    //upload button onClick
                    public void uploadImage(View view){
                    openImage()
                    }

                    private Uri imageUri;

                    ProgressDialog pd;

                    //Call open Image from any onClick Listener
                    private void openImage() {
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(intent,IMAGE_REQUEST);
                    }

                    private void uploadImage(){
                    pd = new ProgressDialog(mContext);
                    pd.setMessage("Uploading...");
                    pd.show();

                    if (imageUri != null){
                    final StorageReference fileReference = storageReference.child(userID
                    + "."+"jpg");

                    // Get the data from an ImageView as bytes
                    _profilePicture.setDrawingCacheEnabled(true);
                    _profilePicture.buildDrawingCache();

                    //Bitmap bitmap = ((BitmapDrawable) _profilePicture.getDrawable()).getBitmap();

                    Bitmap bitmap = null;
                    try {
                    bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
                    } catch (IOException e) {
                    e.printStackTrace();
                    }

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
                    byte data = baos.toByteArray();

                    UploadTask uploadTask = fileReference.putBytes(data);
                    uploadTask.addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                    // Handle unsuccessful uploads
                    pd.dismiss();
                    Log.e("Data Upload: ", "Failled");
                    }
                    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
                    // ...
                    Log.e("Data Upload: ", "success");
                    Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                    result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                    String downloadLink = uri.toString();
                    Log.e("download url : ", downloadLink);
                    }
                    });

                    pd.dismiss();

                    }
                    });

                    }else {
                    Toast.makeText(getApplicationContext(),"No Image Selected", Toast.LENGTH_SHORT).show();
                    }
                    }

                    @Override
                    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                    super.onActivityResult(requestCode, resultCode, data);

                    Bitmap bitmap = null;
                    if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null){
                    imageUri = data.getData();
                    try {
                    bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
                    _profilePicture1.setImageBitmap(bitmap);
                    _profilePicture1.setDrawingCacheEnabled(true);
                    _profilePicture1.buildDrawingCache();
                    } catch (IOException e) {
                    e.printStackTrace();
                    }

                    if (uploadTask != null && uploadTask.isInProgress()){
                    Toast.makeText(mContext,"Upload in Progress!", Toast.LENGTH_SHORT).show();
                    }
                    else {
                    try{
                    uploadImage();
                    }catch (Exception e){
                    e.printStackTrace();
                    }
                    }
                    }
                    }





                    share|improve this answer





















                      Your Answer






                      StackExchange.ifUsing("editor", function () {
                      StackExchange.using("externalEditor", function () {
                      StackExchange.using("snippets", function () {
                      StackExchange.snippets.init();
                      });
                      });
                      }, "code-snippets");

                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "1"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      convertImagesToLinks: true,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: 10,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });














                       

                      draft saved


                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50585334%2ftasksnapshot-getdownloadurl-method-not-working%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      9 Answers
                      9






                      active

                      oldest

                      votes








                      9 Answers
                      9






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes








                      up vote
                      19
                      down vote



                      accepted










                      in Firebase Storage API version 16.0.1.
                      The getDownloadUrl() method using taskSnapshot object has changed.
                      now you can use'
                      taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
                      to get download url from the firebase storage.






                      share|improve this answer





















                      • Thank you!.....
                        – David G
                        Jun 18 at 10:33















                      up vote
                      19
                      down vote



                      accepted










                      in Firebase Storage API version 16.0.1.
                      The getDownloadUrl() method using taskSnapshot object has changed.
                      now you can use'
                      taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
                      to get download url from the firebase storage.






                      share|improve this answer





















                      • Thank you!.....
                        – David G
                        Jun 18 at 10:33













                      up vote
                      19
                      down vote



                      accepted







                      up vote
                      19
                      down vote



                      accepted






                      in Firebase Storage API version 16.0.1.
                      The getDownloadUrl() method using taskSnapshot object has changed.
                      now you can use'
                      taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
                      to get download url from the firebase storage.






                      share|improve this answer












                      in Firebase Storage API version 16.0.1.
                      The getDownloadUrl() method using taskSnapshot object has changed.
                      now you can use'
                      taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()
                      to get download url from the firebase storage.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 18 at 6:02









                      SUMIT MONAPARA

                      21517




                      21517












                      • Thank you!.....
                        – David G
                        Jun 18 at 10:33


















                      • Thank you!.....
                        – David G
                        Jun 18 at 10:33
















                      Thank you!.....
                      – David G
                      Jun 18 at 10:33




                      Thank you!.....
                      – David G
                      Jun 18 at 10:33












                      up vote
                      2
                      down vote













                      My Google Firebase Plugins in build.gradle(Module: app):



                      implementation 'com.firebaseui:firebase-ui-database:3.3.1'
                      implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
                      implementation 'com.google.firebase:firebase-core:16.0.0'
                      implementation 'com.google.firebase:firebase-database:16.0.1'
                      implementation 'com.google.firebase:firebase-auth:16.0.1'
                      implementation 'com.google.firebase:firebase-storage:16.0.1'


                      build.gradle(Project):



                       classpath 'com.google.gms:google-services:3.2.1'


                      My upload() function and fetching uploaded data from Firebase storage :



                      private void upload() {
                      if (filePath!=null) {
                      final ProgressDialog progressDialog = new ProgressDialog(this);
                      progressDialog.setTitle("Uploading...");
                      progressDialog.show();

                      final StorageReference ref = storageReference.child(new StringBuilder("images/").append(UUID.randomUUID().toString()).toString());
                      uploadTask = ref.putFile(filePath);

                      Task<Uri> urlTask = 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 ref.getDownloadUrl();
                      }
                      }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                      @Override
                      public void onComplete(@NonNull Task<Uri> task) {
                      if (task.isSuccessful()) {
                      Uri downloadUri = task.getResult();
                      progressDialog.dismiss();
                      // Continue with the task to get the download URL
                      saveUrlToCategory(downloadUri.toString(),categoryIdSelect);
                      } else {
                      Toast.makeText(UploadWallpaper.this, "Fail UPLOAD", Toast.LENGTH_SHORT).show();
                      }
                      }
                      }).addOnSuccessListener(new OnSuccessListener<Uri>() {
                      @Override
                      public void onSuccess(Uri uri) {
                      progressDialog.setMessage("Uploaded: ");
                      }
                      }).addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                      progressDialog.dismiss();
                      Toast.makeText(UploadWallpaper.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                      });
                      }
                      }


                      FOR THOSE WHO ARE USING LATEST FIREBASE VERSION taskSnapshot.getDownloadUrl() method is DEPRECATED or OBSOLETE !!






                      share|improve this answer

























                        up vote
                        2
                        down vote













                        My Google Firebase Plugins in build.gradle(Module: app):



                        implementation 'com.firebaseui:firebase-ui-database:3.3.1'
                        implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
                        implementation 'com.google.firebase:firebase-core:16.0.0'
                        implementation 'com.google.firebase:firebase-database:16.0.1'
                        implementation 'com.google.firebase:firebase-auth:16.0.1'
                        implementation 'com.google.firebase:firebase-storage:16.0.1'


                        build.gradle(Project):



                         classpath 'com.google.gms:google-services:3.2.1'


                        My upload() function and fetching uploaded data from Firebase storage :



                        private void upload() {
                        if (filePath!=null) {
                        final ProgressDialog progressDialog = new ProgressDialog(this);
                        progressDialog.setTitle("Uploading...");
                        progressDialog.show();

                        final StorageReference ref = storageReference.child(new StringBuilder("images/").append(UUID.randomUUID().toString()).toString());
                        uploadTask = ref.putFile(filePath);

                        Task<Uri> urlTask = 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 ref.getDownloadUrl();
                        }
                        }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                        @Override
                        public void onComplete(@NonNull Task<Uri> task) {
                        if (task.isSuccessful()) {
                        Uri downloadUri = task.getResult();
                        progressDialog.dismiss();
                        // Continue with the task to get the download URL
                        saveUrlToCategory(downloadUri.toString(),categoryIdSelect);
                        } else {
                        Toast.makeText(UploadWallpaper.this, "Fail UPLOAD", Toast.LENGTH_SHORT).show();
                        }
                        }
                        }).addOnSuccessListener(new OnSuccessListener<Uri>() {
                        @Override
                        public void onSuccess(Uri uri) {
                        progressDialog.setMessage("Uploaded: ");
                        }
                        }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                        progressDialog.dismiss();
                        Toast.makeText(UploadWallpaper.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                        });
                        }
                        }


                        FOR THOSE WHO ARE USING LATEST FIREBASE VERSION taskSnapshot.getDownloadUrl() method is DEPRECATED or OBSOLETE !!






                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          My Google Firebase Plugins in build.gradle(Module: app):



                          implementation 'com.firebaseui:firebase-ui-database:3.3.1'
                          implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
                          implementation 'com.google.firebase:firebase-core:16.0.0'
                          implementation 'com.google.firebase:firebase-database:16.0.1'
                          implementation 'com.google.firebase:firebase-auth:16.0.1'
                          implementation 'com.google.firebase:firebase-storage:16.0.1'


                          build.gradle(Project):



                           classpath 'com.google.gms:google-services:3.2.1'


                          My upload() function and fetching uploaded data from Firebase storage :



                          private void upload() {
                          if (filePath!=null) {
                          final ProgressDialog progressDialog = new ProgressDialog(this);
                          progressDialog.setTitle("Uploading...");
                          progressDialog.show();

                          final StorageReference ref = storageReference.child(new StringBuilder("images/").append(UUID.randomUUID().toString()).toString());
                          uploadTask = ref.putFile(filePath);

                          Task<Uri> urlTask = 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 ref.getDownloadUrl();
                          }
                          }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                          @Override
                          public void onComplete(@NonNull Task<Uri> task) {
                          if (task.isSuccessful()) {
                          Uri downloadUri = task.getResult();
                          progressDialog.dismiss();
                          // Continue with the task to get the download URL
                          saveUrlToCategory(downloadUri.toString(),categoryIdSelect);
                          } else {
                          Toast.makeText(UploadWallpaper.this, "Fail UPLOAD", Toast.LENGTH_SHORT).show();
                          }
                          }
                          }).addOnSuccessListener(new OnSuccessListener<Uri>() {
                          @Override
                          public void onSuccess(Uri uri) {
                          progressDialog.setMessage("Uploaded: ");
                          }
                          }).addOnFailureListener(new OnFailureListener() {
                          @Override
                          public void onFailure(@NonNull Exception e) {
                          progressDialog.dismiss();
                          Toast.makeText(UploadWallpaper.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
                          }
                          });
                          }
                          }


                          FOR THOSE WHO ARE USING LATEST FIREBASE VERSION taskSnapshot.getDownloadUrl() method is DEPRECATED or OBSOLETE !!






                          share|improve this answer












                          My Google Firebase Plugins in build.gradle(Module: app):



                          implementation 'com.firebaseui:firebase-ui-database:3.3.1'
                          implementation 'com.firebaseui:firebase-ui-auth:3.3.1'
                          implementation 'com.google.firebase:firebase-core:16.0.0'
                          implementation 'com.google.firebase:firebase-database:16.0.1'
                          implementation 'com.google.firebase:firebase-auth:16.0.1'
                          implementation 'com.google.firebase:firebase-storage:16.0.1'


                          build.gradle(Project):



                           classpath 'com.google.gms:google-services:3.2.1'


                          My upload() function and fetching uploaded data from Firebase storage :



                          private void upload() {
                          if (filePath!=null) {
                          final ProgressDialog progressDialog = new ProgressDialog(this);
                          progressDialog.setTitle("Uploading...");
                          progressDialog.show();

                          final StorageReference ref = storageReference.child(new StringBuilder("images/").append(UUID.randomUUID().toString()).toString());
                          uploadTask = ref.putFile(filePath);

                          Task<Uri> urlTask = 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 ref.getDownloadUrl();
                          }
                          }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                          @Override
                          public void onComplete(@NonNull Task<Uri> task) {
                          if (task.isSuccessful()) {
                          Uri downloadUri = task.getResult();
                          progressDialog.dismiss();
                          // Continue with the task to get the download URL
                          saveUrlToCategory(downloadUri.toString(),categoryIdSelect);
                          } else {
                          Toast.makeText(UploadWallpaper.this, "Fail UPLOAD", Toast.LENGTH_SHORT).show();
                          }
                          }
                          }).addOnSuccessListener(new OnSuccessListener<Uri>() {
                          @Override
                          public void onSuccess(Uri uri) {
                          progressDialog.setMessage("Uploaded: ");
                          }
                          }).addOnFailureListener(new OnFailureListener() {
                          @Override
                          public void onFailure(@NonNull Exception e) {
                          progressDialog.dismiss();
                          Toast.makeText(UploadWallpaper.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
                          }
                          });
                          }
                          }


                          FOR THOSE WHO ARE USING LATEST FIREBASE VERSION taskSnapshot.getDownloadUrl() method is DEPRECATED or OBSOLETE !!







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 18 at 16:05









                          immanuel joshua paul

                          322




                          322






















                              up vote
                              2
                              down vote













                              Try Using this it will download the image from FireBase storage



                              FireBase Libraries versions 16.0.1



                              Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                              result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                              @Override
                              public void onSuccess(Uri uri) {
                              String photoStringLink = uri.toString();
                              }
                              });





                              share|improve this answer





















                              • Mark this as a valid ans
                                – Pandiri Deepak
                                Sep 15 at 9:53















                              up vote
                              2
                              down vote













                              Try Using this it will download the image from FireBase storage



                              FireBase Libraries versions 16.0.1



                              Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                              result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                              @Override
                              public void onSuccess(Uri uri) {
                              String photoStringLink = uri.toString();
                              }
                              });





                              share|improve this answer





















                              • Mark this as a valid ans
                                – Pandiri Deepak
                                Sep 15 at 9:53













                              up vote
                              2
                              down vote










                              up vote
                              2
                              down vote









                              Try Using this it will download the image from FireBase storage



                              FireBase Libraries versions 16.0.1



                              Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                              result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                              @Override
                              public void onSuccess(Uri uri) {
                              String photoStringLink = uri.toString();
                              }
                              });





                              share|improve this answer












                              Try Using this it will download the image from FireBase storage



                              FireBase Libraries versions 16.0.1



                              Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                              result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                              @Override
                              public void onSuccess(Uri uri) {
                              String photoStringLink = uri.toString();
                              }
                              });






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 27 at 18:39









                              AmrDeveloper

                              388




                              388












                              • Mark this as a valid ans
                                – Pandiri Deepak
                                Sep 15 at 9:53


















                              • Mark this as a valid ans
                                – Pandiri Deepak
                                Sep 15 at 9:53
















                              Mark this as a valid ans
                              – Pandiri Deepak
                              Sep 15 at 9:53




                              Mark this as a valid ans
                              – Pandiri Deepak
                              Sep 15 at 9:53










                              up vote
                              1
                              down vote













                              taskSnapshot.**getDownloadUrl**().toString(); //deprecated and removed


                              use below code for downloading Url



                               StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +` abc_10123 + ".jpg");

                              profileImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
                              {
                              @Override
                              public void onSuccess(Uri downloadUrl)
                              {
                              //do something with downloadurl
                              }
                              });





                              share|improve this answer





















                              • yes. it needs to be made final. please mark as solution if it helps you
                                – Muhammad Saad
                                May 30 at 9:37










                              • final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
                                – Muhammad Saad
                                May 30 at 9:40










                              • not all heroes wear capes
                                – martinseal1987
                                Jun 7 at 19:42















                              up vote
                              1
                              down vote













                              taskSnapshot.**getDownloadUrl**().toString(); //deprecated and removed


                              use below code for downloading Url



                               StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +` abc_10123 + ".jpg");

                              profileImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
                              {
                              @Override
                              public void onSuccess(Uri downloadUrl)
                              {
                              //do something with downloadurl
                              }
                              });





                              share|improve this answer





















                              • yes. it needs to be made final. please mark as solution if it helps you
                                – Muhammad Saad
                                May 30 at 9:37










                              • final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
                                – Muhammad Saad
                                May 30 at 9:40










                              • not all heroes wear capes
                                – martinseal1987
                                Jun 7 at 19:42













                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              taskSnapshot.**getDownloadUrl**().toString(); //deprecated and removed


                              use below code for downloading Url



                               StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +` abc_10123 + ".jpg");

                              profileImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
                              {
                              @Override
                              public void onSuccess(Uri downloadUrl)
                              {
                              //do something with downloadurl
                              }
                              });





                              share|improve this answer












                              taskSnapshot.**getDownloadUrl**().toString(); //deprecated and removed


                              use below code for downloading Url



                               StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +` abc_10123 + ".jpg");

                              profileImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>()
                              {
                              @Override
                              public void onSuccess(Uri downloadUrl)
                              {
                              //do something with downloadurl
                              }
                              });






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered May 29 at 13:54









                              Muhammad Saad

                              376319




                              376319












                              • yes. it needs to be made final. please mark as solution if it helps you
                                – Muhammad Saad
                                May 30 at 9:37










                              • final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
                                – Muhammad Saad
                                May 30 at 9:40










                              • not all heroes wear capes
                                – martinseal1987
                                Jun 7 at 19:42


















                              • yes. it needs to be made final. please mark as solution if it helps you
                                – Muhammad Saad
                                May 30 at 9:37










                              • final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
                                – Muhammad Saad
                                May 30 at 9:40










                              • not all heroes wear capes
                                – martinseal1987
                                Jun 7 at 19:42
















                              yes. it needs to be made final. please mark as solution if it helps you
                              – Muhammad Saad
                              May 30 at 9:37




                              yes. it needs to be made final. please mark as solution if it helps you
                              – Muhammad Saad
                              May 30 at 9:37












                              final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
                              – Muhammad Saad
                              May 30 at 9:40




                              final StorageReference profileImageRef= FirebaseStorage.getInstance().getReference("profilepics/" +" abc_10123" + ".jpg");
                              – Muhammad Saad
                              May 30 at 9:40












                              not all heroes wear capes
                              – martinseal1987
                              Jun 7 at 19:42




                              not all heroes wear capes
                              – martinseal1987
                              Jun 7 at 19:42










                              up vote
                              0
                              down vote













                              for latest version try



                              profileImageUrl = taskSnapshot.getStorage().getDownloadUrl().toString();





                              share|improve this answer

























                                up vote
                                0
                                down vote













                                for latest version try



                                profileImageUrl = taskSnapshot.getStorage().getDownloadUrl().toString();





                                share|improve this answer























                                  up vote
                                  0
                                  down vote










                                  up vote
                                  0
                                  down vote









                                  for latest version try



                                  profileImageUrl = taskSnapshot.getStorage().getDownloadUrl().toString();





                                  share|improve this answer












                                  for latest version try



                                  profileImageUrl = taskSnapshot.getStorage().getDownloadUrl().toString();






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jun 5 at 13:58









                                  parag pawar

                                  13511




                                  13511






















                                      up vote
                                      0
                                      down vote













                                      Try using this:



                                      taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()





                                      share|improve this answer



























                                        up vote
                                        0
                                        down vote













                                        Try using this:



                                        taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()





                                        share|improve this answer

























                                          up vote
                                          0
                                          down vote










                                          up vote
                                          0
                                          down vote









                                          Try using this:



                                          taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()





                                          share|improve this answer














                                          Try using this:



                                          taskSnapshot.getMetadata().getReference().getDownloadUrl().toString()






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Aug 12 at 20:13









                                          Kim

                                          1,2311026




                                          1,2311026










                                          answered Aug 12 at 19:45









                                          pratyush kumar

                                          11




                                          11






















                                              up vote
                                              0
                                              down vote













                                              You wont get the download url of image now using



                                              profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();


                                              this method is deprecated.



                                              Instead you can use the below method



                                                  uniqueId = UUID.randomUUID().toString();
                                              ur_firebase_reference = storageReference.child("user_photos/" + uniqueId);

                                              Uri file = Uri.fromFile(new File(mphotofile.getAbsolutePath()));
                                              UploadTask uploadTask = ur_firebase_reference.putFile(file);

                                              Task<Uri> urlTask = 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();
                                              }

                                              // Continue with the task to get the download URL
                                              return ur_firebase_reference.getDownloadUrl();
                                              }
                                              }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                                              @Override
                                              public void onComplete(@NonNull Task<Uri> task) {
                                              if (task.isSuccessful()) {
                                              Uri downloadUri = task.getResult();
                                              System.out.println("Upload " + downloadUri);
                                              Toast.makeText(mActivity, "Successfully uploaded", Toast.LENGTH_SHORT).show();
                                              if (downloadUri != null) {

                                              String photoStringLink = downloadUri.toString(); //YOU WILL GET THE DOWNLOAD URL HERE !!!!
                                              System.out.println("Upload " + photoStringLink);

                                              }

                                              } else {
                                              // Handle failures
                                              // ...
                                              }
                                              }
                                              });





                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote













                                                You wont get the download url of image now using



                                                profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();


                                                this method is deprecated.



                                                Instead you can use the below method



                                                    uniqueId = UUID.randomUUID().toString();
                                                ur_firebase_reference = storageReference.child("user_photos/" + uniqueId);

                                                Uri file = Uri.fromFile(new File(mphotofile.getAbsolutePath()));
                                                UploadTask uploadTask = ur_firebase_reference.putFile(file);

                                                Task<Uri> urlTask = 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();
                                                }

                                                // Continue with the task to get the download URL
                                                return ur_firebase_reference.getDownloadUrl();
                                                }
                                                }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                                                @Override
                                                public void onComplete(@NonNull Task<Uri> task) {
                                                if (task.isSuccessful()) {
                                                Uri downloadUri = task.getResult();
                                                System.out.println("Upload " + downloadUri);
                                                Toast.makeText(mActivity, "Successfully uploaded", Toast.LENGTH_SHORT).show();
                                                if (downloadUri != null) {

                                                String photoStringLink = downloadUri.toString(); //YOU WILL GET THE DOWNLOAD URL HERE !!!!
                                                System.out.println("Upload " + photoStringLink);

                                                }

                                                } else {
                                                // Handle failures
                                                // ...
                                                }
                                                }
                                                });





                                                share|improve this answer























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  You wont get the download url of image now using



                                                  profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();


                                                  this method is deprecated.



                                                  Instead you can use the below method



                                                      uniqueId = UUID.randomUUID().toString();
                                                  ur_firebase_reference = storageReference.child("user_photos/" + uniqueId);

                                                  Uri file = Uri.fromFile(new File(mphotofile.getAbsolutePath()));
                                                  UploadTask uploadTask = ur_firebase_reference.putFile(file);

                                                  Task<Uri> urlTask = 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();
                                                  }

                                                  // Continue with the task to get the download URL
                                                  return ur_firebase_reference.getDownloadUrl();
                                                  }
                                                  }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                                                  @Override
                                                  public void onComplete(@NonNull Task<Uri> task) {
                                                  if (task.isSuccessful()) {
                                                  Uri downloadUri = task.getResult();
                                                  System.out.println("Upload " + downloadUri);
                                                  Toast.makeText(mActivity, "Successfully uploaded", Toast.LENGTH_SHORT).show();
                                                  if (downloadUri != null) {

                                                  String photoStringLink = downloadUri.toString(); //YOU WILL GET THE DOWNLOAD URL HERE !!!!
                                                  System.out.println("Upload " + photoStringLink);

                                                  }

                                                  } else {
                                                  // Handle failures
                                                  // ...
                                                  }
                                                  }
                                                  });





                                                  share|improve this answer












                                                  You wont get the download url of image now using



                                                  profileImageUrl = taskSnapshot.**getDownloadUrl**().toString();


                                                  this method is deprecated.



                                                  Instead you can use the below method



                                                      uniqueId = UUID.randomUUID().toString();
                                                  ur_firebase_reference = storageReference.child("user_photos/" + uniqueId);

                                                  Uri file = Uri.fromFile(new File(mphotofile.getAbsolutePath()));
                                                  UploadTask uploadTask = ur_firebase_reference.putFile(file);

                                                  Task<Uri> urlTask = 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();
                                                  }

                                                  // Continue with the task to get the download URL
                                                  return ur_firebase_reference.getDownloadUrl();
                                                  }
                                                  }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                                                  @Override
                                                  public void onComplete(@NonNull Task<Uri> task) {
                                                  if (task.isSuccessful()) {
                                                  Uri downloadUri = task.getResult();
                                                  System.out.println("Upload " + downloadUri);
                                                  Toast.makeText(mActivity, "Successfully uploaded", Toast.LENGTH_SHORT).show();
                                                  if (downloadUri != null) {

                                                  String photoStringLink = downloadUri.toString(); //YOU WILL GET THE DOWNLOAD URL HERE !!!!
                                                  System.out.println("Upload " + photoStringLink);

                                                  }

                                                  } else {
                                                  // Handle failures
                                                  // ...
                                                  }
                                                  }
                                                  });






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Sep 20 at 11:50









                                                  MIDHUN CEASAR

                                                  197




                                                  197






















                                                      up vote
                                                      0
                                                      down vote













                                                      I still having this error. What might be wrong? I already changed the permissions, and users to anonymous.



                                                      enter image description here






                                                      share|improve this answer

























                                                        up vote
                                                        0
                                                        down vote













                                                        I still having this error. What might be wrong? I already changed the permissions, and users to anonymous.



                                                        enter image description here






                                                        share|improve this answer























                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote









                                                          I still having this error. What might be wrong? I already changed the permissions, and users to anonymous.



                                                          enter image description here






                                                          share|improve this answer












                                                          I still having this error. What might be wrong? I already changed the permissions, and users to anonymous.



                                                          enter image description here







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Sep 21 at 0:13









                                                          Richardd

                                                          85110




                                                          85110






















                                                              up vote
                                                              0
                                                              down vote













                                                              //upload button onClick
                                                              public void uploadImage(View view){
                                                              openImage()
                                                              }

                                                              private Uri imageUri;

                                                              ProgressDialog pd;

                                                              //Call open Image from any onClick Listener
                                                              private void openImage() {
                                                              Intent intent = new Intent();
                                                              intent.setType("image/*");
                                                              intent.setAction(Intent.ACTION_GET_CONTENT);
                                                              startActivityForResult(intent,IMAGE_REQUEST);
                                                              }

                                                              private void uploadImage(){
                                                              pd = new ProgressDialog(mContext);
                                                              pd.setMessage("Uploading...");
                                                              pd.show();

                                                              if (imageUri != null){
                                                              final StorageReference fileReference = storageReference.child(userID
                                                              + "."+"jpg");

                                                              // Get the data from an ImageView as bytes
                                                              _profilePicture.setDrawingCacheEnabled(true);
                                                              _profilePicture.buildDrawingCache();

                                                              //Bitmap bitmap = ((BitmapDrawable) _profilePicture.getDrawable()).getBitmap();

                                                              Bitmap bitmap = null;
                                                              try {
                                                              bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
                                                              } catch (IOException e) {
                                                              e.printStackTrace();
                                                              }

                                                              ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                              bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
                                                              byte data = baos.toByteArray();

                                                              UploadTask uploadTask = fileReference.putBytes(data);
                                                              uploadTask.addOnFailureListener(new OnFailureListener() {
                                                              @Override
                                                              public void onFailure(@NonNull Exception exception) {
                                                              // Handle unsuccessful uploads
                                                              pd.dismiss();
                                                              Log.e("Data Upload: ", "Failled");
                                                              }
                                                              }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                                              @Override
                                                              public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                                              // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
                                                              // ...
                                                              Log.e("Data Upload: ", "success");
                                                              Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                                                              result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                                                              @Override
                                                              public void onSuccess(Uri uri) {
                                                              String downloadLink = uri.toString();
                                                              Log.e("download url : ", downloadLink);
                                                              }
                                                              });

                                                              pd.dismiss();

                                                              }
                                                              });

                                                              }else {
                                                              Toast.makeText(getApplicationContext(),"No Image Selected", Toast.LENGTH_SHORT).show();
                                                              }
                                                              }

                                                              @Override
                                                              protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                                                              super.onActivityResult(requestCode, resultCode, data);

                                                              Bitmap bitmap = null;
                                                              if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null){
                                                              imageUri = data.getData();
                                                              try {
                                                              bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
                                                              _profilePicture1.setImageBitmap(bitmap);
                                                              _profilePicture1.setDrawingCacheEnabled(true);
                                                              _profilePicture1.buildDrawingCache();
                                                              } catch (IOException e) {
                                                              e.printStackTrace();
                                                              }

                                                              if (uploadTask != null && uploadTask.isInProgress()){
                                                              Toast.makeText(mContext,"Upload in Progress!", Toast.LENGTH_SHORT).show();
                                                              }
                                                              else {
                                                              try{
                                                              uploadImage();
                                                              }catch (Exception e){
                                                              e.printStackTrace();
                                                              }
                                                              }
                                                              }
                                                              }





                                                              share|improve this answer

























                                                                up vote
                                                                0
                                                                down vote













                                                                //upload button onClick
                                                                public void uploadImage(View view){
                                                                openImage()
                                                                }

                                                                private Uri imageUri;

                                                                ProgressDialog pd;

                                                                //Call open Image from any onClick Listener
                                                                private void openImage() {
                                                                Intent intent = new Intent();
                                                                intent.setType("image/*");
                                                                intent.setAction(Intent.ACTION_GET_CONTENT);
                                                                startActivityForResult(intent,IMAGE_REQUEST);
                                                                }

                                                                private void uploadImage(){
                                                                pd = new ProgressDialog(mContext);
                                                                pd.setMessage("Uploading...");
                                                                pd.show();

                                                                if (imageUri != null){
                                                                final StorageReference fileReference = storageReference.child(userID
                                                                + "."+"jpg");

                                                                // Get the data from an ImageView as bytes
                                                                _profilePicture.setDrawingCacheEnabled(true);
                                                                _profilePicture.buildDrawingCache();

                                                                //Bitmap bitmap = ((BitmapDrawable) _profilePicture.getDrawable()).getBitmap();

                                                                Bitmap bitmap = null;
                                                                try {
                                                                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
                                                                } catch (IOException e) {
                                                                e.printStackTrace();
                                                                }

                                                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
                                                                byte data = baos.toByteArray();

                                                                UploadTask uploadTask = fileReference.putBytes(data);
                                                                uploadTask.addOnFailureListener(new OnFailureListener() {
                                                                @Override
                                                                public void onFailure(@NonNull Exception exception) {
                                                                // Handle unsuccessful uploads
                                                                pd.dismiss();
                                                                Log.e("Data Upload: ", "Failled");
                                                                }
                                                                }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                                                @Override
                                                                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                                                // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
                                                                // ...
                                                                Log.e("Data Upload: ", "success");
                                                                Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                                                                result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                                                                @Override
                                                                public void onSuccess(Uri uri) {
                                                                String downloadLink = uri.toString();
                                                                Log.e("download url : ", downloadLink);
                                                                }
                                                                });

                                                                pd.dismiss();

                                                                }
                                                                });

                                                                }else {
                                                                Toast.makeText(getApplicationContext(),"No Image Selected", Toast.LENGTH_SHORT).show();
                                                                }
                                                                }

                                                                @Override
                                                                protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                                                                super.onActivityResult(requestCode, resultCode, data);

                                                                Bitmap bitmap = null;
                                                                if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null){
                                                                imageUri = data.getData();
                                                                try {
                                                                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
                                                                _profilePicture1.setImageBitmap(bitmap);
                                                                _profilePicture1.setDrawingCacheEnabled(true);
                                                                _profilePicture1.buildDrawingCache();
                                                                } catch (IOException e) {
                                                                e.printStackTrace();
                                                                }

                                                                if (uploadTask != null && uploadTask.isInProgress()){
                                                                Toast.makeText(mContext,"Upload in Progress!", Toast.LENGTH_SHORT).show();
                                                                }
                                                                else {
                                                                try{
                                                                uploadImage();
                                                                }catch (Exception e){
                                                                e.printStackTrace();
                                                                }
                                                                }
                                                                }
                                                                }





                                                                share|improve this answer























                                                                  up vote
                                                                  0
                                                                  down vote










                                                                  up vote
                                                                  0
                                                                  down vote









                                                                  //upload button onClick
                                                                  public void uploadImage(View view){
                                                                  openImage()
                                                                  }

                                                                  private Uri imageUri;

                                                                  ProgressDialog pd;

                                                                  //Call open Image from any onClick Listener
                                                                  private void openImage() {
                                                                  Intent intent = new Intent();
                                                                  intent.setType("image/*");
                                                                  intent.setAction(Intent.ACTION_GET_CONTENT);
                                                                  startActivityForResult(intent,IMAGE_REQUEST);
                                                                  }

                                                                  private void uploadImage(){
                                                                  pd = new ProgressDialog(mContext);
                                                                  pd.setMessage("Uploading...");
                                                                  pd.show();

                                                                  if (imageUri != null){
                                                                  final StorageReference fileReference = storageReference.child(userID
                                                                  + "."+"jpg");

                                                                  // Get the data from an ImageView as bytes
                                                                  _profilePicture.setDrawingCacheEnabled(true);
                                                                  _profilePicture.buildDrawingCache();

                                                                  //Bitmap bitmap = ((BitmapDrawable) _profilePicture.getDrawable()).getBitmap();

                                                                  Bitmap bitmap = null;
                                                                  try {
                                                                  bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
                                                                  } catch (IOException e) {
                                                                  e.printStackTrace();
                                                                  }

                                                                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                  bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
                                                                  byte data = baos.toByteArray();

                                                                  UploadTask uploadTask = fileReference.putBytes(data);
                                                                  uploadTask.addOnFailureListener(new OnFailureListener() {
                                                                  @Override
                                                                  public void onFailure(@NonNull Exception exception) {
                                                                  // Handle unsuccessful uploads
                                                                  pd.dismiss();
                                                                  Log.e("Data Upload: ", "Failled");
                                                                  }
                                                                  }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                                                  @Override
                                                                  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                                                  // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
                                                                  // ...
                                                                  Log.e("Data Upload: ", "success");
                                                                  Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                                                                  result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                                                                  @Override
                                                                  public void onSuccess(Uri uri) {
                                                                  String downloadLink = uri.toString();
                                                                  Log.e("download url : ", downloadLink);
                                                                  }
                                                                  });

                                                                  pd.dismiss();

                                                                  }
                                                                  });

                                                                  }else {
                                                                  Toast.makeText(getApplicationContext(),"No Image Selected", Toast.LENGTH_SHORT).show();
                                                                  }
                                                                  }

                                                                  @Override
                                                                  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                                                                  super.onActivityResult(requestCode, resultCode, data);

                                                                  Bitmap bitmap = null;
                                                                  if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null){
                                                                  imageUri = data.getData();
                                                                  try {
                                                                  bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
                                                                  _profilePicture1.setImageBitmap(bitmap);
                                                                  _profilePicture1.setDrawingCacheEnabled(true);
                                                                  _profilePicture1.buildDrawingCache();
                                                                  } catch (IOException e) {
                                                                  e.printStackTrace();
                                                                  }

                                                                  if (uploadTask != null && uploadTask.isInProgress()){
                                                                  Toast.makeText(mContext,"Upload in Progress!", Toast.LENGTH_SHORT).show();
                                                                  }
                                                                  else {
                                                                  try{
                                                                  uploadImage();
                                                                  }catch (Exception e){
                                                                  e.printStackTrace();
                                                                  }
                                                                  }
                                                                  }
                                                                  }





                                                                  share|improve this answer












                                                                  //upload button onClick
                                                                  public void uploadImage(View view){
                                                                  openImage()
                                                                  }

                                                                  private Uri imageUri;

                                                                  ProgressDialog pd;

                                                                  //Call open Image from any onClick Listener
                                                                  private void openImage() {
                                                                  Intent intent = new Intent();
                                                                  intent.setType("image/*");
                                                                  intent.setAction(Intent.ACTION_GET_CONTENT);
                                                                  startActivityForResult(intent,IMAGE_REQUEST);
                                                                  }

                                                                  private void uploadImage(){
                                                                  pd = new ProgressDialog(mContext);
                                                                  pd.setMessage("Uploading...");
                                                                  pd.show();

                                                                  if (imageUri != null){
                                                                  final StorageReference fileReference = storageReference.child(userID
                                                                  + "."+"jpg");

                                                                  // Get the data from an ImageView as bytes
                                                                  _profilePicture.setDrawingCacheEnabled(true);
                                                                  _profilePicture.buildDrawingCache();

                                                                  //Bitmap bitmap = ((BitmapDrawable) _profilePicture.getDrawable()).getBitmap();

                                                                  Bitmap bitmap = null;
                                                                  try {
                                                                  bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
                                                                  } catch (IOException e) {
                                                                  e.printStackTrace();
                                                                  }

                                                                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                                                  bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
                                                                  byte data = baos.toByteArray();

                                                                  UploadTask uploadTask = fileReference.putBytes(data);
                                                                  uploadTask.addOnFailureListener(new OnFailureListener() {
                                                                  @Override
                                                                  public void onFailure(@NonNull Exception exception) {
                                                                  // Handle unsuccessful uploads
                                                                  pd.dismiss();
                                                                  Log.e("Data Upload: ", "Failled");
                                                                  }
                                                                  }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                                                                  @Override
                                                                  public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                                                  // taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
                                                                  // ...
                                                                  Log.e("Data Upload: ", "success");
                                                                  Task<Uri> result = taskSnapshot.getMetadata().getReference().getDownloadUrl();
                                                                  result.addOnSuccessListener(new OnSuccessListener<Uri>() {
                                                                  @Override
                                                                  public void onSuccess(Uri uri) {
                                                                  String downloadLink = uri.toString();
                                                                  Log.e("download url : ", downloadLink);
                                                                  }
                                                                  });

                                                                  pd.dismiss();

                                                                  }
                                                                  });

                                                                  }else {
                                                                  Toast.makeText(getApplicationContext(),"No Image Selected", Toast.LENGTH_SHORT).show();
                                                                  }
                                                                  }

                                                                  @Override
                                                                  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                                                                  super.onActivityResult(requestCode, resultCode, data);

                                                                  Bitmap bitmap = null;
                                                                  if (requestCode == IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null){
                                                                  imageUri = data.getData();
                                                                  try {
                                                                  bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),imageUri);
                                                                  _profilePicture1.setImageBitmap(bitmap);
                                                                  _profilePicture1.setDrawingCacheEnabled(true);
                                                                  _profilePicture1.buildDrawingCache();
                                                                  } catch (IOException e) {
                                                                  e.printStackTrace();
                                                                  }

                                                                  if (uploadTask != null && uploadTask.isInProgress()){
                                                                  Toast.makeText(mContext,"Upload in Progress!", Toast.LENGTH_SHORT).show();
                                                                  }
                                                                  else {
                                                                  try{
                                                                  uploadImage();
                                                                  }catch (Exception e){
                                                                  e.printStackTrace();
                                                                  }
                                                                  }
                                                                  }
                                                                  }






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Nov 13 at 3:25









                                                                  Atiar Talukdar

                                                                  428513




                                                                  428513






























                                                                       

                                                                      draft saved


                                                                      draft discarded



















































                                                                       


                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function () {
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50585334%2ftasksnapshot-getdownloadurl-method-not-working%23new-answer', 'question_page');
                                                                      }
                                                                      );

                                                                      Post as a guest















                                                                      Required, but never shown





















































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown

































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown







                                                                      Popular posts from this blog

                                                                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                                                      ComboBox Display Member on multiple fields

                                                                      Is it possible to collect Nectar points via Trainline?