I want to fetch Url of the Image that I have uploaded in the Firebase. To fetch the Image I need to have the Url of the specific Image. But there's is problem occurring in the fetching. The Output box shows the following:
error: incompatible types: Task cannot be converted to Uri
If I use Task<Uri> the image url become different. As compare to Uri.
private void startPosting() { if (filePath != null) { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle("Uploading..."); progressDialog.show(); final StorageReference ref = mStorage.child("Quote_Image" + UUID.randomUUID().toString()); ref.putFile(filePath) .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { progressDialog.dismiss(); Toast.makeText(adminUpdateQuotesSend.this , "Uploaded" , Toast.LENGTH_SHORT).show(); mDatbase = FirebaseDatabase.getInstance().getReference().child("Quotes"); DatabaseReference newPost = mDatbase.push(); Uri down=ref.getDownloadUrl(); Uri dow=down; newPost.child("ImageUrl").setValue(ref.getDownloadUrl()); // newPost.child("Positivity").setValue(PositiveDesc); } }) .addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() { @Override public void onProgress(UploadTask.TaskSnapshot taskSnapshot) { double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot .getTotalByteCount()); progressDialog.setMessage("Uploaded " + (int) progress + "%"); } }); } } The error is flashing on this line of code:
Uri down=ref.getDownloadUrl();
getDownloadUrlreturns a task, which then gives you the download URL once it completes. For a code sample of how to do this, see stackoverflow.com/questions/51056397/… and the longer: firebase.google.com/docs/storage/android/…