Update contact is not working using lookupUri

Put your problem here if it does not fit any of the other categories.

Update contact is not working using lookupUri

Postby twishadv » Mon Mar 14, 2011 8:30 am

I am trying to add and update contacts to the phone book through my application. I am using the lookup key to uniquely identify the contact before updating. Below is my code snippet for getting the unique contact to be updated:

Code: Select all
Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
Uri res = ContactsContract.Contacts.lookupContact(context.getContentResolver(), lookupUri);
Cursor t_cursor = context.getContentResolver().query(res, null, null, null, null);
String t_id = t_cursor.getString(t_cursor.getColumnIndex(ContactsContract.Contacts.Data._ID));
String t_contactId = t_cursor.getString(t_cursor.getColumnIndex(ContactsContract.Contacts._ID));


After obtaining the contact I am updating it as follows:

Code: Select all
            String Where = ContactsContract.Contacts.Data._ID + " = '"+t_id+"'";
//            String Where = ContactsContract.Contacts.Data._ID + " = '"+t_id+"' AND"+ContactsContract.Contacts._ID +" = '" +t_contactId+" '" ;
            ContentValues values = new ContentValues();
            values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, modified_name+"P");
            values.put(Email.TYPE, Email.TYPE_WORK);
            values.put(Email.DATA, email);
            values.put(Organization.TITLE, title);
            values.put(Organization.COMPANY, "XYZ");
            context.getContentResolver().update(Data.CONTENT_URI, values, Where, null);


But nothing is getting updated. It is not giving any error but still is not working. Could anyone suggest where am I going wrong ?
twishadv
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Mar 14, 2011 8:19 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 21 guests