Can't get download url from Firebase Storge in Android [duplicate]

Can't get download url from Firebase Storge in Android. I get:

com.google.android.gms.tasks.zzn@

Instead of the url download link. My code:

storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
            public void onSuccess(Uri uri) {
                uri1=uri;
                downloadURL =uri.toString();
                            // Got the download URL for 'users/me/profile.png'
            }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                             public void onFailure(@NonNull Exception exception) {
                                 // Handle any errors
                             }
             });

 if(uri1==null&&downloadURL==null){
                 Toast.makeText(MainActivity.this, "error", Toast.LENGTH_SHORT).show();
             }else if(uri1==null){
                Toast.makeText(MainActivity.this, ""+downloadURL, Toast.LENGTH_SHORT).show();
             }else if(downloadURL==null) {
                            Toast.makeText(MainActivity.this, "" + uri1, Toast.LENGTH_SHORT).show();
             }

thank u


In order to get the url, you need to attach a listener. So to solve this, please use the following code:

ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        String uri = uri.toString();
        Log.d("TAG", uri);
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle Errors
    }
});