当我在聊天系统中发送图像时,它崩溃并显示此错误:
List<Map<String,String>>
我可以将图像存储到Firebase存储器中,但不能将其存储在Firebase实时数据库中。
Found conflicting getters for name: isFocusable
该数据库将在用户输入文本并发送时生成,如果用户正在发送图像,则数据库结构几乎相同,只是“类型”会将其更改为图像,而“消息”则不存储文本。它存储
这样的uri @Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri imageUri = data.getData();
databaseReference = FirebaseDatabase.getInstance().getReference().child("Chats");
final StorageReference fileReference = storageReference.child(System.currentTimeMillis()
+ "." + getFileExtension(imageUri));
final String id = firebaseUser.getUid();
final String key = firebaseDatabase.getReference("Chats").push().getKey();
mUploadTask = fileReference.putFile(imageUri);
mUploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
return fileReference.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
String downloadUrl = task.getResult().toString();
final HashMap<String, Object> messageMap = new HashMap();
messageMap.put("Key", key);
messageMap.put("Sender", id);
messageMap.put("Receiver", userid);
messageMap.put("Message", downloadUrl);
messageMap.put("isseen", false);
messageMap.put("time", time);
messageMap.put("type", "image");
System.out.println("haha chat " + downloadUrl);
databaseReference.child(key).updateChildren(messageMap);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "" + e, Toast.LENGTH_LONG).show();
System.out.println("haha chat e " + e);
}
});
}
}
模型类
https://firebasestorage.googleapis.com/v0/b/final-year-project-51c9a.appspot.com/o/Chat%20Images%2F1551454994072.jpg?alt=media&token=6ef744f8-0a7c-42a3-b5ba-9ea660a0ec76
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
尝试将那些数据传递给另一种方法,并将其添加到数据库中。它应该可以工作