i've put down some code to upload image to my firebase storage and then retrive the url to use it to show the image as a profile pic for my application android.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 2 && resultCode == RESULT_OK){
Uri uri = data.getData();
StorageReference filepath = mStorage.child("Photos").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Map<String, Object> data = new HashMap<>();
data.put("ProfilePic", filepath.toString());
db.collection("Accounts").document(user.getUid())
.set(data, SetOptions.merge())
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "DocumentSnapshot successfully written!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error writing document", e);
}
});
}
});
}
}
with the filepath variable, i use it to save the url of my image into the database inside the account folder. So every pic has a unique profile reference.
The problem is the return value of filepath. It shows the path inside firebase for example
gs://eyesee-gd23b.appspot.com/image/44405857
so i try to use
filepath.getDownloadUrl()
but instead of the url that i can see it on firebase webpage, i retrieve something like
com.google.android.gms.tasks.zzu@dsd873
any suggest?