Thursday, June 10, 2010

[android-developers] Weird contact behavior in 2.1 - adding phone number

I am using the code below to add a phone number to a contact. The code
works in some cases and not others.

1. On the 2.1update1 emulator it works all the time
2. On a Nexus One 2.1update1 phone it works when I create a new
contact manually, then use my app with the code below to add a phone
number to said contact
3. On the same phone, when the app adds a phone number to a contact
that existed from before (tied to a gmail account), the api call
succeeds with no exception but it does not add the new number in to
the contact.
4. The update of one phone number to another works 100% of the time.

What gives with #3?
Jay

------------
Adding phone number to existing contact (does not work in Case 3
above):
{
ArrayList<ContentProviderOperation> ops = new
ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, rawcontactID)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, PhoneNumber)
.withValue(Phone.TYPE, Phone.TYPE_MOBILE)
.build());
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY,
ops);
}

Updating phone number in existing contact (works all the time):
{
ArrayList<ContentProviderOperation> operation = new
ArrayList<ContentProviderOperation>();
operation.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withSelection(Data._ID+ "=?", new String[]
{String.valueOf(contactID)})
.withValue(Phone.TYPE, phonetype)
.withValue(Phone.NUMBER, PhoneNumber)
.build());
context.getContentResolver().applyBatch(ContactsContract.AUTHORITY,
operation);
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment