我正在尝试在Firebase存储数据库中实现照片存储。我使用的教程针对较旧版本的firebase进行了显示,结果导致代码中出现了一些错误。请帮我调试一下。请给我具体的说明/更改,因为我对此很陌生,并且不会理解任何通用命令。谢谢
private void saveUserInformation() {
name = mNameField.getText().toString();
phone = mPhoneField.getText().toString();
Map userInfo = new HashMap();
userInfo.put("name", name);
userInfo.put("phone", phone);
mCustomerDatabase.updateChildren(userInfo);
if(resultUri != null){
StorageReference filepath = FirebaseStorage.getInstance().getReference().child("profileImages").child(userId);
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getApplication().getContentResolver(), resultUri);
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = filepath.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
finish();
}
});
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl(); //THIS LINE GIVES ME THE ERROR
Map userInfo = new HashMap();
userInfo.put("profileImageUrl", downloadUrl.toString());
mCustomerDatabase.updateChildren(userInfo);
finish();
return;
}
});
}else{
finish();
}
}
尝试使用:
taskSnapshot.getMetadata().getReference().getDownloadUrl()