0

I am new to Android, currently I can retrieve contact list and image from Google contact. However, the contact list from my App does not provide suggestion for email within my company like the Google Gmail app.

Is it possible that I can retrieve these extra email addresses?

Below is the code to retrieve contact

public ArrayList<String> getNameEmailDetails() {
    ArrayList<String> emlRecs = new ArrayList<String>();
    HashSet<String> emlRecsHS = new HashSet<String>();
    ContentResolver cr = getContentResolver();
    String[] PROJECTION = new String[] { ContactsContract.RawContacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts.PHOTO_ID,
            ContactsContract.CommonDataKinds.Email.DATA,
            ContactsContract.CommonDataKinds.Photo.CONTACT_ID };
    String order = "CASE WHEN "
            + ContactsContract.Contacts.DISPLAY_NAME
            + " NOT LIKE '%@%' THEN 1 ELSE 2 END, "
            + ContactsContract.Contacts.DISPLAY_NAME
            + ", "
            + ContactsContract.CommonDataKinds.Email.DATA
            + " COLLATE NOCASE";
    String filter = ContactsContract.CommonDataKinds.Email.DATA + " NOT LIKE ''";
    Cursor cur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, PROJECTION, filter, null, order);
    if (cur.moveToFirst()) {
        do {
            // names comes in hand sometimes
            String name = cur.getString(1);
            String email = cur.getString(3);
            String contact_id = cur.getString(4);
            Bitmap profilePic = openPhoto(Long.parseLong(contact_id));
            if (profilePic != null) {
                profileList.add(new WordMatchAdapterWithIMG.profileWithIMG(email, profilePic));
            }
        } while (cur.moveToNext());
    }

    cur.close();
    return emlRecs;
}

1 Answers1

0

I would suggest you use the Google Contacts API.

The Google Contacts API allows client applications to view and update a user's contacts. Contacts are stored in the user's Google Account; most Google services have access to the contact list.

To retrieve a single contact, send an authorized GET request to the contact's selfLink URL:

https://www.google.com/m8/feeds/contacts/{userEmail}/full/{contactId}

Upon success, the server responds with an HTTP 200 OK status code and the requested contact entry.

public static ContactEntry retrieveContact(ContactsService myService) { ContactEntry contact = myService.getEntry(new URL("https://www.google.com/m8/feeds/contacts/default/full/contactId"), ContactEntry.class); // Do something with the contact. return contact; }

Useful Materials

Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91