tamir7 / Contacts

Android Contacts API
287 stars 74 forks source link

ENHANCEMENT: Fetch Contacts via CONTACT_LAST_UPDATED_TIMESTAMP #36

Closed rayliverified closed 6 years ago

rayliverified commented 7 years ago

Behavior: Pass date to Contacts API which fetches all contacts with ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP later than passed value.

Usage: This would be a useful enhancement to detect changes to the contact database. Whenever a Content Observer detects a change in the contacts database, it could fetch the changed contacts based on the CONTACT_LAST_UPDATED_TIMESTAMP. This allows for efficient contacts management as it removes the need to iterate through the entire contacts library when changes are detected.

rayliverified commented 7 years ago

The following code gets the contacts by their last updated date.

        String lastupdate = lastupdate;
        Cursor c = mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.CONTACT_LAST_UPDATED_TIMESTAMP + " > ?", new String[] {lastupdate}, null);
        if (c.moveToFirst()) {
            do {
                Contact contact = new Contact();
                contact.setID(c.getInt(c.getColumnIndex(ContactsContract.Contacts._ID)));
                contactList.add(contact);
                Log.d("Contact ID", String.valueOf(contact.getID()));
            }
            while (c.moveToNext());
        }
        c.close();

Hope someone can integrate it into the library!

rayliverified commented 6 years ago

Closing due to inactivity.