Replacing the deprecated taskSnapshot.getDownloadUrl().toString();
getDownloadUrl()
is deprecated so you need to use Task and check isComplete()
like below to see if it is completed
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICTURE_RESULT && resultCode == RESULT_OK) {
Uri imageUri = data.getData();
StorageReference ref = FirebaseUtil.mStorageRef.child(imageUri.getLastPathSegment());
ref.putFile(imageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Task<Uri> uri = taskSnapshot.getStorage().getDownloadUrl();
while(!uri.isComplete());
Uri url = uri.getResult();
Log.i(TAG, url.toString());
deal.setImageUrl(url.toString());
taskSnapshot.getDownloadUrl() method not working
Edit: see this comment on why the approach in this answer doesn't work:
firebaser here This answer is wrong. While it at first may appear to work (since it compiles) the result of
getDownloadUrl().toString()
is not a download URL, but a string representation of aTask
object. For a better answer, see stackoverflow.com/a/55503926 or the sample in the Firebase documentation.
Original answer below...
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.
Firebase Storage getDownloadUrl() method can't be resolved
The Firebase API has changed.
May 23, 2018
Cloud Storage version 16.0.1
Removed the deprecated StorageMetadata.getDownloadUrl() and UploadTask.TaskSnapshot.getDownloadUrl() methods. To get a current download URL, use StorageReference.getDownloadUr().
UploadTask.TaskSnapshot
has a method named getMetadata()
which returns a StorageMetadata
object.
This StorageMetadata
object contains a method named getReference()
which returns a StorageReference
object.
That StorageReference
object contains the getDownloadUrl()
method, which now returns a Task object instead of an Uri object.
This Task must then be listened upon in order to obtain the Uri, which can be done asynchronously or in a blocking manner; see the Tasks API for that.
Related Topics
Stuck with Getting Camera Pic When Using the Tab Activity
How to Use the Android Volley API
How to Calculate Dp from Pixels in Android Programmatically
How to Show One Layout on Top of the Other Programmatically in My Case
Android Room - Get the Id of New Inserted Row with Auto-Generate
How to Install Android Market App on the Emulator
Surfacetexture's Onframeavailable() Method Always Called Too Late
Restrict Edittext to Single Line
Whatsapp Message Layout - How to Get Time-View in the Same Row
Manipulating Data on Webs in Android
Image Size (Drawable-Hdpi/Ldpi/Mdpi/Xhdpi)
Handling Back Button in Android Navigation Component
Android in App Purchase: Signature Verification Failed
How to Clear Cookies and Cache of Webview on Android When Not in Webview
How to Get the Mobile Number of Current Sim Card in Real Device