/** * Check whether the provided email address belongs to one of the contacts. * * @param emailAddress The email address to look for. * @return <tt>true</tt>, if the email address belongs to a contact. * <tt>false</tt>, otherwise. */ public boolean isInContacts(final String emailAddress) { boolean result = false; final Cursor c = getContactByAddress(emailAddress); if (c != null) { if (c.getCount() > 0) { result = true; } c.close(); } return result; }
/** * Get the name of the contact an email address belongs to. * * @param address The email address to search for. * @return The name of the contact the email address belongs to. Or * <tt>null</tt> if there's no matching contact. */ public String getNameForAddress(String address) { if (address == null) { return null; } else if (nameCache.containsKey(address)) { return nameCache.get(address); } final Cursor c = getContactByAddress(address); String name = null; if (c != null) { if (c.getCount() > 0) { c.moveToFirst(); name = c.getString(NAME_INDEX); } c.close(); } nameCache.put(address, name); return name; }
/** * Mark contacts with the provided email addresses as contacted. * * @param addresses Array of {@link Address} objects describing the * contacts to be marked as contacted. */ public void markAsContacted(final Address[] addresses) { //TODO: Optimize! Potentially a lot of database queries for (final Address address : addresses) { final Cursor c = getContactByAddress(address.getAddress()); if (c != null) { if (c.getCount() > 0) { c.moveToFirst(); final long personId = c.getLong(CONTACT_ID_INDEX); ContactsContract.Contacts.markAsContacted(mContentResolver, personId); } c.close(); } } }
final Cursor c = getContactByAddress(address); if (c == null) { return null;