gpt4 book ai didi

java - 如何访问firebase数组

转载 作者:行者123 更新时间:2023-12-01 16:30:11 25 4
gpt4 key购买 nike

如何在Android中访问指纹数组?我不知道该怎么办。

DatabaseReference dbTITO = FirebaseDatabase.getInstance().getReference("Employee/2/fingerprint");
dbTITO.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
byte[] imageFinger = dataSnapshot.child("fingerprint").getValue();

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});

enter image description here员工2代码:2部门名称:“刺客”指纹0:01:2482:1263:14:2005:426:227

最佳答案

只要您使用像 Employee/2/fingerprint 这样的引用,就无需再次调用 child("fingerprint")。要解决此问题,请使用以下代码行:

DatabaseReference fingerprintRef = rootRef.child("Employee").child("2").child("fingerprint");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long count = dataSnapshot.getChildrenCount();
byte[] bytes = new byte[(int) count];
int count = 0;
for(DataSnapshot ds : dataSnapshot.getChildren()) {
long value = ds.getValue(Long.class);
bytes[count] = (byte) value;
count++;
}

//Do what you need to do with your array
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("TAG", databaseError.getMessage()); //Don't ignore errors!
}
};
fingerprintRef.addListenerForSingleValueEvent(valueEventListener);

关于java - 如何访问firebase数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62059918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com