Firebase查询未响应子事件侦听器。实际上我正在尝试将手机中的电话号码与Firebase数据库中的电话号码进行比较,并且我已经实施了Firebase查询......这不能按预期工作。 这是我的代码
private Firebase userLocationRef = new Firebase("https://XXXX-XXX.fiXXXXXo.cXX/users");
ContentResolver cr = this.getContentResolver(); //Activity/Application android.content.Context
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (cursor.moveToFirst()) {
do {
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{id}, null);
while (pCur.moveToNext()) {
final String contactNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
//All Mapping Stuff to be done here..
Log.e("Phone Number", contactNumber);
com.firebase.client.Query query = userLocationRef.orderByChild("phoneNumber").equalTo(contactNumber);
query.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.e("Contact Found", "Got Value");
dataSource.createContact(contactNumber);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.e("Contact Found", "Got Value again");
dataSource.createContact(contactNumber);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Log.e("Contact Found", "Got Value again");
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Log.e("Contact Found", "Got Value again");
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.e("Contact Found", "Got Value again");
}
});
break;
}
pCur.close();
}
} while (cursor.moveToNext());
}
}
和最后但不是最少这里是我在Firebase中的dataBase树
Root
+ friends
- users
- 9xx888xxx
hasLoggedIn: false
name:"XXXXXXXXXX"
phoneNumber:"9xx888xxx"
+ timeStampJoinedaddclose
+ 989xxxx898
+ xxxx000000