Try to do this:
private String generatedFilePath;
myStorage.child("picture").child("pic_one.jpg").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'pic_one.jpg'
Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
generatedFilePath = downloadUri.toString(); /// The string(file link) that you need
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
Also, it is not possible to get the downloadURL from the root of the storage tree. You should store the downloadURL of the file programmatically to your database in order to access it later on, so first upload the photo to your storage and then in the onSuccess you should upload the downloadURL to your database, then retrieve it from there.
In order to do this you should first declare your databaseReference
private DatabaseReference mDatabase;
// ...
mDatabase = FirebaseDatabase.getInstance().getReference();
and then, after you upload succefully your picture to the storage, grab the downloadURL and post it to your database
this is an example from the official doc
Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg"));
StorageReference riversRef = storageRef.child("images/"+file.getLastPathSegment());
uploadTask = riversRef.putFile(file);
// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Uri downloadUrl = taskSnapshot.getDownloadUrl(); //After uploading your picture you can get the download url of it
mDatabase.child("images").setValue(downloadUrl); //and then you save it in your database
}
});
and then just remember to get the downloadURL from the database like this:
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String downloadURL = dataSnapshot.getValue(String.class);
//do whatever you want with the download url
}