After studying more in detail ContactMethods, I realized that I was
using the wrong ID. Below is the code excerpt which does the job
correctly. Hope it helps someone else as well.
-Ali
.
.
private static final int PEOPLE__ID_COLUMN_INDEX = 0;
private static final int PEOPLE_NAME_COLUMN_INDEX = 1;
private static final int CONTACTMETHODS_ID_COLUMN_INDEX = 0;
.
.
.
String[] projectionPeople = new String[] { People._ID, People.NAME };
Cursor peopleCur = getContentResolver().query(People.CONTENT_URI,
projectionPeople, null, null, People.NAME);
Uri.Builder builder = People.CONTENT_URI.buildUpon();
if (null != peopleCur)
{
if (peopleCur.moveToFirst())
{
String peopleID = peopleCur.getString(PEOPLE__ID_COLUMN_INDEX);
String where = Contacts.ContactMethods.PERSON_ID + " == " +
peopleID
+ " AND "
+ Contacts.ContactMethods.KIND + " == "
+ Contacts.KIND_EMAIL;
String[] projectionContactMethods = new String[]
{ Contacts.ContactMethods._ID };
Cursor addrCur =
getContentResolver().query(Contacts.ContactMethods.CONTENT_URI,
projectionContactMethods, where, null,
null);
if (null != addrCur)
{
if ( addrCur.moveToFirst() )
{
String contactMethodsID =
addrCur.getString(CONTACTMETHODS_ID_COLUMN_INDEX);
ContentValues contentValues = new ContentValues();
contentValues.put( People.ContactMethods.KIND,
Contacts.KIND_EMAIL);
contentValues.put( People.ContactMethods.DATA,
"[email protected]" );
contentValues.put( People.ContactMethods.TYPE,
People.ContactMethods.TYPE_WORK );
builder.encodedPath(People.ContactMethods.CONTENT_DIRECTORY +
"/" + contactMethodsID);
getContentResolver().update( builder.build(), contentValues,
null, null );
}
addrCur.close();
}
}
peopleCur.close();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en