0

I have created an application for ContactsContract... I have created a spinner which brings all the accounts configured and hence the user can pick up the contact type say, gmail(com.google), phoneBook and so on....

Now, If I select phoneBook, then the contact gets added in the phoneBook perfectly. When I select gmail option, It works perfectly on my htc cell phone... The contact gets added, and after sync, I can see that in my gmail account too.

But, the same thing when I test on any of the samsung cell phones, it does not get added to the contacts of my gmail....

I am confused...

Any help is appreciated. Thanks in advance...

Bhavin
  • 6,020
  • 4
  • 24
  • 26
kanchan
  • 77
  • 3
  • 11

1 Answers1

0

Phone numbers are stored in their own table and need to be queried separately. To query the phone number table use the URI stored in the SDK variable ContactsContract.CommonDataKinds.Phone.CONTENT_URI. Use a WHERE conditional to get the phone numbers for the specified contact.

if (Integer.parseInt(cur.getString(
       cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
    Cursor pCur = cr.query(
    ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
    null, 
    ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", 
    new String[]{id}, null);
    while (pCur.moveToNext()) {
    // Do something with phones
    } 
    pCur.close();
}

Perform a second query against the Android contacts SQLite database. The phone numbers are queried against the URI stored in ContactsContract.CommonDataKinds.Phone.CONTENT_URI. The contact ID is stored in the phone table as ContactsContract.CommonDataKinds.Phone.CONTACT_ID and the WHERE clause is used to limit the data returned.

Email Addresses

Querying email addresses is similar to phone numbers. A query must be performed to get email addresses from the database. Query the URI stored in ContactsContract.CommonDataKinds.Email.CONTENT_URI to query the email address table.

Cursor emailCur = cr.query( 
        ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
        null,
        ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
        new String[]{id}, null); 
    while (emailCur.moveToNext()) { 
        // This would allow you get several email addresses
            // if the email addresses were stored in an array
        String email = emailCur.getString(
                      emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
        String emailType = emailCur.getString(
                      emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
    } 
    emailCur.close();
Nimit
  • 1,714
  • 3
  • 22
  • 33