How can I retrieve contact events synced from Google Contacts without a year?
I'm using the code below to retrieve a cursor for events and contacts and it's working just fine for events with a year specified. Unfortunately, events where only the day and month are set are not returned by this query.
I have set these dates in Google Contacts for some contact birthdays and I'm wondering if I need to use RawContacts rather than ContactsContract to get these values?
Update: It seems that events entered into the phone without a year are retrieved. It is only events added via http://www.google.com/contacts that are not retrieved. I can see these events in the Cont开发者_如何学Pythonacts app though - displayed as something like --05-23
.
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
Event.CONTACT_ID,
Event.START_DATE,
Event.TYPE
};
Cursor c = mContext.getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
projection,
ContactsContract.Data.MIMETYPE + "= ?",
new String[] { Event.CONTENT_ITEM_TYPE },
Event.START_DATE);
c.moveToFirst();
int nameIndex = c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
int dateIndex = c.getColumnIndex(Event.START_DATE);
String name, date;
while (c.moveToNext()) {
name = c.getString(nameIndex);
date = c.getString(dateIndex);
Log.d(TAG, "Event for " + name + " is " + date);
}
c.close();
I'm running on the Nexus S (2.3.4) and I have used your exact code and I get all contacts printed out including ones with no year.
07-19 17:08:36.847: DEBUG/test(24646): Event for Warren Upton is --12-01
07-19 17:08:36.851: DEBUG/test(24646): Event for Marion Atkins is 1934-11-24
Can you give any more details on how to reproduce the problem?
I'm guessing events with no year don't have Event.START_DATE
set (since by definition a date would be day/month/year). If you remove it from the projection and sort do they get retrieved?
精彩评论