Aah ! I actually found the solution ! :)
On Jun 19, 6:48 pm, Deepak <[EMAIL PROTECTED]> wrote:
> Hello All,
>
> Does anyone know how to retrieve email ids from added contacts.
>
> I was able to add email ids programmatically using the following code
> snippet below, but I could not retrieve it ! :(
>
> try {
> ContentValues person = new ContentValues();
> person.put(Contacts.People.NAME, "Smith John,
> Mr.");
> person.put(Contacts.People.COMPANY, "Test
> Company");
> person.put(Contacts.People.NOTES, "eNotes");
>
> Uri newPerson =
> PhoneBook.this.getContentResolver().insert(
> Contacts.People.CONTENT_URI,
> person);
>
> if (newPerson != null) {
> List pathList =
> newPerson.getPathSegments();
> String pathLeaf = (String) pathList
> .get(pathList.size()
> - 1);
>
> // add mobile phone number
> ContentValues number = new
> ContentValues();
> number.put(Contacts.Phones.PERSON_ID,
> pathLeaf);
> number.put(Contacts.Phones.NUMBER,
> "(408) 111-1111");
> number.put(Contacts.Phones.TYPE,
>
> Contacts.Phones.MOBILE_TYPE);
> Uri phoneUpdate =
> PhoneBook.this.getContentResolver()
>
> .insert(Contacts.Phones.CONTENT_URI, number);
> if (phoneUpdate == null) {
> throw new Exception(
> "Failed to
> insert mobile phone number");
> }
>
> // add fax number
> number = new ContentValues();
> number.put(Contacts.Phones.PERSON_ID,
> pathLeaf);
> number.put(Contacts.Phones.NUMBER,
> "(408) 111-1111-1");
> number.put(Contacts.Phones.TYPE,
>
> Contacts.Phones.WORK_FAX_TYPE);
> phoneUpdate =
> PhoneBook.this.getContentResolver().insert(
>
> Contacts.Phones.CONTENT_URI, number);
> if (phoneUpdate == null) {
> throw new Exception("Failed
> to insert work fax number");
> }
>
> // add email
> ContentValues email = new
> ContentValues();
>
> email.put(Contacts.ContactMethods.PERSON_ID, pathLeaf);
>
> email.put(Contacts.ContactMethods.KIND,
>
> Contacts.ContactMethods.EMAIL_KIND);
>
> email.put(Contacts.ContactMethods.DATA,
> "[EMAIL PROTECTED]");
>
> email.put(Contacts.ContactMethods.TYPE,
>
> Contacts.ContactMethods.EMAIL_KIND_PRIMARY_TYPE);
> Uri emailUpdate =
> PhoneBook.this.getContentResolver()
> .insert(
>
> Uri.withAppendedPath(newPerson,
>
> Contacts.ContactMethods.CONTENT_URI
>
> .getPath().substring(1)),
>
> email);
> if (emailUpdate == null) {
> throw new Exception("Failed
> to insert primary email");
> }
>
> // add postal address
> ContentValues address = new
> ContentValues();
>
> address.put(Contacts.ContactMethods.PERSON_ID, pathLeaf);
>
> address.put(Contacts.ContactMethods.KIND,
>
> Contacts.ContactMethods.POSTAL_KIND);
>
> address.put(Contacts.ContactMethods.DATA,
> "Baker Street
> 14\n54123 New Hampshire");
>
> address.put(Contacts.ContactMethods.TYPE,
>
> Contacts.ContactMethods.POSTAL_KIND_POSTAL_TYPE);
> Uri addressUpdate =
> PhoneBook.this.getContentResolver()
> .insert(
>
> Uri.withAppendedPath(newPerson,
>
> Contacts.ContactMethods.CONTENT_URI
>
> .getPath().substring(1)),
>
> address);
> if (addressUpdate == null) {
> throw new Exception("Failed
> to insert primary email");
> }
> }
>
> } catch (Exception e) {
> Log.e("GuiAndroid", "Failed to add contact
> due to:" + e, e);
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---