如何仅检索密钥内的电子邮件地址,而不是所有项目。我有一个项目名称和电子邮件,但我只想检索EMAIL。
示例:
public static void main(String[] args) {
// Sort the data
int[] array = {1,5,2,3,6,2,29,-2,23,3};
int temp;
for (int i = 0; i<array.length-1; i++) {
if (array[i] > array[i+1]) {
temp=array[i+1]; //temporel
array[i+1] = array[i];
array[i] = temp;
i=0; //to return to the start of the array
}
}
// Print the data.
for (int i = 0; i<array.length; i++) {
System.out.print(i+ ", ");
}
}
答案 0 :(得分:0)
首先将数据库引用为
mReference= FirebaseDatabase.getInstance().getReferenceFromUrl(FIREBASE_URL_USERS);
这里FREBASE_URL_USERS是一个用户密钥的网址,你可以从firebase控制台获取它。 它是您的unique_fiirebase_root_url / User01
的组合然后获取数据快照
mDatabseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getValue("Email");
// use log to check whetehr you are getting email or not
@Override
public void onCancelled(DatabaseError databaseError) {
// log error and do something
}
});
答案 1 :(得分:0)
假设用户的电子邮件是唯一的,您可以通过电子邮件值query用户记录,如下所示:
final String email = "hani.mehdi@email.com";
ValueEventListener onFindListener = new ValueEventListener() {
@Override
public void onCancelled(DatabaseError error) {
Log.e(TAG, error.getMessage());
}
@Override
public void onDataChange(DataSnapshot snapshot) {
Map<String, User> result = snapshot.getValue(Map.class);
if (result.contains(email) {
User user = result.get(email);
Log.i(TAG, user.toString());
} else {
Log.d(TAG, "Not found: " + email);
}
}
};
DatabaseReference userReference = database.getReference("users")
.orderByChild("email")
.equalTo(email)
.addListenerForSingleValueEvent(onFindListener);