How to use getdownloadurl in recent versions?
The taskSnapshot.getDownloadUrl()
method was removed in recent versions of the Firebase Storage SDK. You will need to instead get the download URL from the StorageReference
now.
Calling StorageReference.getDownloadUrl()
returns a Task
, since it needs to retrieve the download URL from the server. So you'll need a completion listener to get the actual URL.
From the documentation on downloading a file:
storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png' in uri
System.out.println(uri.toString());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
Alternatively that first line could be this if you're getting the download URL right after uploading (as in your case):
taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
Also see:
- Firebase Storage getDownloadUrl() method can't be resolved
- Error: cannot find symbol method getDownloadUrl() of type com.google.firebase.storage.UploadTask.TaskSnapshot
- The example in the Firebase documentation on uploading a file and getting its download URL
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.
Android Studio can't get Storage download URL
Could you try this:
fileReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Download URL
String url = uri.toString();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Errors
}
});
Related Topics
Android Marshmallow Request Permission
Failed to Resolve: Com.Android.Support:Cardview-V7:26.0.0 Android
How to Implement a Viewpager With Different Fragments/Layouts
Re-Launch of Activity on Home Button, But...Only the First Time
Android Gallery on Android 4.4 (Kitkat) Returns Different Uri For Intent.Action_Get_Content
Disable Back Button in Android
Difference Between Activity Context and Application Context
Building and Running App Via Gradle and Android Studio Is Slower Than Via Eclipse
How to Stop Edittext from Gaining Focus When an Activity Starts in Android
Making Textview Scrollable on Android
How to Start My App When the Phone Starts on Android
Google Maps Android API V2 - Interactive Infowindow (Like in Original Android Google Maps)
Dexindexoverflowexception Only When Running Tests