Do one table query per contact

This commit is contained in:
macdonst 2010-10-08 03:25:56 +08:00
parent 50ab0e0834
commit 4a6105de6b

View File

@ -55,7 +55,6 @@ import android.webkit.WebView;
*/ */
public class ContactAccessorSdk5 extends ContactAccessor { public class ContactAccessorSdk5 extends ContactAccessor {
private static final String WHERE_STRING = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
private static final Map<String, String> dbMap = new HashMap<String, String>(); private static final Map<String, String> dbMap = new HashMap<String, String>();
static { static {
dbMap.put("id", ContactsContract.Contacts._ID); dbMap.put("id", ContactsContract.Contacts._ID);
@ -142,59 +141,109 @@ public class ContactAccessorSdk5 extends ContactAccessor {
Iterator<String> it = contactIds.iterator(); Iterator<String> it = contactIds.iterator();
JSONArray contacts = new JSONArray(); JSONArray contacts = new JSONArray();
JSONObject contact;
String contactId; String contactId;
int pos = 0; int pos = 0;
String[] events = null; boolean firstRow = true;
while (it.hasNext() && (pos < limit)) { while (it.hasNext() && (pos < limit)) {
contact = new JSONObject(); JSONObject contact = new JSONObject();
JSONArray organizations = new JSONArray();
JSONArray addresses = new JSONArray();
JSONArray phones = new JSONArray();
JSONArray emails = new JSONArray();
JSONArray ims = new JSONArray();
JSONArray websites = new JSONArray();
JSONArray relationships = new JSONArray();
contactId = it.next(); contactId = it.next();
Cursor c = cr.query(ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.CONTACT_ID + " = ?",
new String[] {contactId},
null);
String mimetype = "";
while (c.moveToNext()) {
try { try {
if (firstRow) {
firstRow = false;
contact.put("id", contactId); contact.put("id", contactId);
if (isRequired("displayName",populate)) { contact.put("displayName", c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
contact.put("displayName", displayNameQuery(cr, contactId));
} }
if (isRequired("name",populate)) { mimetype = c.getString(c.getColumnIndex(ContactsContract.Data.MIMETYPE));
contact.put("name", nameQuery(cr, contactId)); if (mimetype.equals(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
&& isRequired("name",populate)) {
contact.put("name", nameQuery(c));
} }
if (isRequired("phoneNumbers",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
contact.put("phoneNumbers", phoneQuery(cr, contactId)); && isRequired("phoneNumbers",populate)) {
phones.put(phoneQuery(c));
} }
if (isRequired("emails",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
contact.put("emails", emailQuery(cr, contactId)); && isRequired("emails",populate)) {
emails.put(emailQuery(c));
} }
if (isRequired("addresses",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
contact.put("addresses", addressQuery(cr, contactId)); && isRequired("addresses",populate)) {
addresses.put(addressQuery(c));
} }
if (isRequired("organizations",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
contact.put("organizations", organizationQuery(cr, contactId)); && isRequired("organizations",populate)) {
organizations.put(organizationQuery(c));
} }
if (isRequired("ims",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE)
contact.put("ims",imQuery(cr, contactId)); && isRequired("ims",populate)) {
ims.put(imQuery(c));
} }
if (isRequired("note",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE)
contact.put("note",noteQuery(cr, contactId)); && isRequired("note",populate)) {
contact.put("note",c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE)));
} }
if (isRequired("nickname",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE)
contact.put("nickname",nicknameQuery(cr, contactId)); && isRequired("nickname",populate)) {
contact.put("nickname",c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME)));
} }
if (isRequired("urls",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE)
contact.put("urls",websiteQuery(cr, contactId)); && isRequired("urls",populate)) {
websites.put(websiteQuery(c));
} }
if (isRequired("relationships",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE)
contact.put("relationships",relationshipQuery(cr, contactId)); && isRequired("relationships",populate)) {
relationships.put(relationshipQuery(c));
} }
if (isRequired("birthday",populate) || isRequired("anniversary",populate)) { if (mimetype.equals(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)) {
events = eventQuery(cr, contactId); if (ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY == c.getInt(c.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))
contact.put("birthday",events[0]); && isRequired("anniversary",populate)) {
contact.put("anniversary",events[1]); contact.put("anniversary", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE)));
} }
} catch (JSONException e) { else if (ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY == c.getInt(c.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))
&& isRequired("birthday",populate)) {
contact.put("birthday", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE)));
}
}
}
catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(),e); Log.e(LOG_TAG, e.getMessage(),e);
} }
Log.d(LOG_TAG, "putting in contact ID = " + contactId); }
c.close();
firstRow = true;
// Populate the Contact object with it's arrays
try {
contact.put("organizations", organizations);
contact.put("addresses", addresses);
contact.put("phoneNumbers", phones);
contact.put("emails", emails);
contact.put("ims", ims);
contact.put("websites", websites);
contact.put("relationships", relationships);
}
catch (JSONException e) {
Log.e(LOG_TAG,e.getMessage(),e);
}
contacts.put(contact); contacts.put(contact);
pos++; pos++;
} }
@ -330,32 +379,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
cursor.close(); cursor.close();
} }
private String displayNameQuery(ContentResolver cr, String contactId) { private JSONObject organizationQuery(Cursor cursor) {
Cursor cursor = cr.query(
ContactsContract.Contacts.CONTENT_URI,
new String[] {ContactsContract.Contacts.DISPLAY_NAME},
ContactsContract.Contacts._ID + " = ?",
new String[] {contactId},
null);
cursor.moveToFirst();
String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
cursor.close();
return displayName;
}
private JSONArray organizationQuery(ContentResolver cr, String contactId) {
String[] orgWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Organization.DEPARTMENT,
ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION,
ContactsContract.CommonDataKinds.Organization.OFFICE_LOCATION,
ContactsContract.CommonDataKinds.Organization.COMPANY,
ContactsContract.CommonDataKinds.Organization.TITLE},
WHERE_STRING, orgWhereParams, null);
JSONArray organizations = new JSONArray();
JSONObject organization = new JSONObject(); JSONObject organization = new JSONObject();
while (cursor.moveToNext()) {
try { try {
organization.put("department", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DEPARTMENT))); organization.put("department", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.DEPARTMENT)));
organization.put("description", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION))); organization.put("description", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.JOB_DESCRIPTION)));
@ -366,29 +391,14 @@ public class ContactAccessorSdk5 extends ContactAccessor {
// TODO no startDate // TODO no startDate
// organization.put("startDate", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization))); // organization.put("startDate", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization)));
organization.put("title", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE))); organization.put("title", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Organization.TITLE)));
organizations.put(organization);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
} return organization;
cursor.close();
return organizations;
} }
private JSONArray addressQuery(ContentResolver cr, String contactId) { private JSONObject addressQuery(Cursor cursor) {
String[] addrWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS,
ContactsContract.CommonDataKinds.StructuredPostal.STREET,
ContactsContract.CommonDataKinds.StructuredPostal.CITY,
ContactsContract.CommonDataKinds.StructuredPostal.REGION,
ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE,
ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY},
WHERE_STRING, addrWhereParams, null);
JSONArray addresses = new JSONArray();
JSONObject address = new JSONObject(); JSONObject address = new JSONObject();
while (cursor.moveToNext()) {
try { try {
address.put("formatted", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS))); address.put("formatted", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS)));
address.put("streetAddress", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET))); address.put("streetAddress", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.STREET)));
@ -396,33 +406,20 @@ public class ContactAccessorSdk5 extends ContactAccessor {
address.put("region", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION))); address.put("region", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.REGION)));
address.put("postalCode", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE))); address.put("postalCode", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE)));
address.put("country", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY))); address.put("country", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY)));
addresses.put(address);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
} return address;
cursor.close();
return addresses;
} }
private JSONObject nameQuery(ContentResolver cr, String contactId) { private JSONObject nameQuery(Cursor cursor) {
String[] addrWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE};
Cursor name = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME,
ContactsContract.CommonDataKinds.StructuredName.PREFIX,
ContactsContract.CommonDataKinds.StructuredName.SUFFIX},
WHERE_STRING, addrWhereParams, null);
JSONObject contactName = new JSONObject(); JSONObject contactName = new JSONObject();
if (name.moveToFirst()) {
try { try {
String familyName = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME)); String familyName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
String givenName = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME)); String givenName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME));
String middleName = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME)); String middleName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME));
String honorificPrefix = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX)); String honorificPrefix = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.PREFIX));
String honorificSuffix = name.getString(name.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX)); String honorificSuffix = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.SUFFIX));
// Create the formatted name // Create the formatted name
StringBuffer formatted = new StringBuffer(""); StringBuffer formatted = new StringBuffer("");
@ -441,163 +438,70 @@ public class ContactAccessorSdk5 extends ContactAccessor {
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
}
name.close();
return contactName; return contactName;
} }
private JSONArray phoneQuery(ContentResolver cr, String contactId) { private JSONObject phoneQuery(Cursor cursor) {
Cursor phones = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Phone.NUMBER,ContactsContract.CommonDataKinds.Phone.TYPE},
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId,
null, null);
JSONArray phoneNumbers = new JSONArray();
JSONObject phoneNumber = new JSONObject(); JSONObject phoneNumber = new JSONObject();
while (phones.moveToNext()) {
try { try {
phoneNumber.put("primary", false); // Android does not store primary attribute phoneNumber.put("primary", false); // Android does not store primary attribute
phoneNumber.put("value", phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))); phoneNumber.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));
phoneNumber.put("type", phones.getInt(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE))); phoneNumber.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE)));
phoneNumbers.put(phoneNumber);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
catch (Exception excp) {
Log.e(LOG_TAG, excp.getMessage(), excp);
} }
phones.close(); return phoneNumber;
return phoneNumbers;
} }
private JSONArray emailQuery(ContentResolver cr, String contactId) { private JSONObject emailQuery(Cursor cursor) {
Cursor emails = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Email.DATA,ContactsContract.CommonDataKinds.Email.TYPE},
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
null, null);
JSONArray emailAddresses = new JSONArray();
JSONObject email = new JSONObject(); JSONObject email = new JSONObject();
while (emails.moveToNext()) {
try { try {
email.put("primary", false); // Android does not store primary attribute email.put("primary", false); // Android does not store primary attribute
email.put("value", emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA))); email.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)));
email.put("type", emails.getInt(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE))); email.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)));
emailAddresses.put(email);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
} return email;
emails.close();
return emailAddresses;
} }
private JSONArray imQuery(ContentResolver cr, String contactId) { private JSONObject imQuery(Cursor cursor) {
String[] addrWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Im.DATA,ContactsContract.CommonDataKinds.Im.TYPE},
WHERE_STRING, addrWhereParams, null);
JSONArray ims = new JSONArray();
JSONObject im = new JSONObject(); JSONObject im = new JSONObject();
while (cursor.moveToNext()) {
try { try {
im.put("primary", false); // Android does not store primary attribute im.put("primary", false); // Android does not store primary attribute
im.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA))); im.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
im.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE))); im.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.TYPE)));
ims.put(im);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
} return im;
cursor.close();
return ims;
} }
private String noteQuery(ContentResolver cr, String contactId) { private JSONObject websiteQuery(Cursor cursor) {
String[] noteWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Note.NOTE}, WHERE_STRING, noteWhereParams, null);
String note = new String("");
if (cursor.moveToFirst()) {
note = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
}
cursor.close();
return note;
}
private String nicknameQuery(ContentResolver cr, String contactId) {
String[] nicknameWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Nickname.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Nickname.NAME}, WHERE_STRING, nicknameWhereParams, null);
String nickname = new String("");
if (cursor.moveToFirst()) {
nickname = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME));
}
cursor.close();
return nickname;
}
private JSONArray websiteQuery(ContentResolver cr, String contactId) {
String[] websiteWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Website.URL,ContactsContract.CommonDataKinds.Website.TYPE},
WHERE_STRING, websiteWhereParams, null);
JSONArray websites = new JSONArray();
JSONObject website = new JSONObject(); JSONObject website = new JSONObject();
while (cursor.moveToNext()) {
try { try {
website.put("primary", false); // Android does not store primary attribute website.put("primary", false); // Android does not store primary attribute
website.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL))); website.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.URL)));
website.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.TYPE))); website.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Website.TYPE)));
websites.put(website);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
} return website;
cursor.close();
return websites;
} }
private JSONArray relationshipQuery(ContentResolver cr, String contactId) { private JSONObject relationshipQuery(Cursor cursor) {
String[] relationshipWhereParams = new String[]{contactId,
ContactsContract.CommonDataKinds.Relation.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.CommonDataKinds.Relation.NAME,ContactsContract.CommonDataKinds.Relation.TYPE},
WHERE_STRING, relationshipWhereParams, null);
JSONArray relationships = new JSONArray();
JSONObject relationship = new JSONObject(); JSONObject relationship = new JSONObject();
while (cursor.moveToNext()) {
try { try {
relationship.put("primary", false); // Android does not store primary attribute relationship.put("primary", false); // Android does not store primary attribute
relationship.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.NAME))); relationship.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.NAME)));
relationship.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.TYPE))); relationship.put("type", cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Relation.TYPE)));
relationships.put(relationship);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG, e.getMessage(), e); Log.e(LOG_TAG, e.getMessage(), e);
} }
} return relationship;
cursor.close();
return relationships;
}
private String[] eventQuery(ContentResolver cr, String contactId) {
String[] whereParams = new String[]{contactId, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE};
Cursor cursor = cr.query(ContactsContract.Data.CONTENT_URI,
null, WHERE_STRING, whereParams, null);
String anniversary = null;
String birthday = null;
while (cursor.moveToNext()) {
if (ContactsContract.CommonDataKinds.Event.TYPE_ANNIVERSARY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
anniversary = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
}
else if (ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY == cursor.getInt(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE))) {
birthday = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));
}
}
cursor.close();
return new String[] {anniversary, birthday};
} }
@Override @Override