【发布时间】:2021-05-04 15:59:29
【问题描述】:
我在我的更新按钮中设置了一个 onclicklistner,我想在 firebasestore(firestore 版本 22.1.2)中上传图像和用户名。我已经在 gradle 中添加了所有 firestore 依赖,getDownloadUrl 不起作用它说找不到符号方法 getDownloadUrl
String user_id = firebaseAuth.getCurrentUser().getUid();
StorageReference image_path = storageReference.child("profile_image").child(user_id+".jpg");
image_path.putFile(mainImageURI).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful()){
Uri download_uri = task.getResult().getDownloadUrl(); //Have error in this getDownloadUrl().
Map<String,String> userMap = new HashMap<>();
userMap.put("name",user_name);
userMap.put("image",download_uri);
firebaseFirestore.collection("Users").document(user_id).set(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
finish();
Toast.makeText(SetupActivity.this,"The User Settings are updated ", Toast.LENGTH_LONG).show();
Intent mainIntent = new Intent(SetupActivity.this, MainActivity.class);
startActivity(mainIntent);
}else {
String error = task.getException().getMessage();
Toast.makeText(SetupActivity.this,"Firestore Error: "+error, Toast.LENGTH_LONG).show();
}
setupProgress.setVisibility(View.INVISIBLE);
}
});
}else{
String error = task.getException().getMessage();
Toast.makeText(SetupActivity.this,"Image Error: "+error, Toast.LENGTH_LONG).show();
setupProgress.setVisibility(View.INVISIBLE);
}
}
});
【问题讨论】:
标签: android firebase firebase-storage