views:

1277

answers:

3

I would like my code to update contact details (like name, phone number, email, organization details, etc) in the android contact book. I was successful in modifying a few (name, phone number and email to be specific) but not all.

Whenever I try to update the organization details (Contacts.Organizations.COMPANY and Contacts.Organizations.TITLE) for a contact my app throws an exception java.lang.UnsupportedOperationException: Cannot update URL: content://contacts/people/69/organizations/69

the code snippet is as follows:

Uri baseUri = ContentUris.withAppendedId(People.CONTENT_URI, 69);
Uri uri = Uri.withAppendedPath(baseUri, People.Phones.CONTENT_DIRECTORY);
Cursor c = this.getContentResolver().query(uri, 
                new String[] { Contacts.Organizations._ID, Contacts.Organizations.COMPANY,Contacts.Organizations.TITLE}, 
                null, null, null);
if(c.getCount() > 0) {
      uri = ContentUris.withAppendedId(uri, c.getString(0));
ContentValues val1 = new ContentValues();
val1.put(Contacts.Organizations.COMPANY, "arw");
val1.put(Contacts.Organizations.TYPE, Contacts.Organizations.TYPE_WORK);
val1.put(Contacts.Organizations.TITLE, "abcdef");
this.getContentResolver().insert(uri, val1);
A: 

All of you contacts should be sync to either gmail, facebook etc...

Mandocaedis
A: 

I spent a lot of time trying to update the company and title information. The following now works for me.

Uri workUri = Uri.withAppendedPath(contactUri, android.provider.Contacts.Organizations.CONTENT_DIRECTORY);
            values.clear();
            values.put(android.provider.Contacts.Organizations.COMPANY, "company");
            values.put(android.provider.Contacts.Organizations.TYPE, android.provider.Contacts.Organizations.TYPE_WORK);
            values.put(android.provider.Contacts.Organizations.TITLE, "job title");
            values.put(android.provider.Contacts.Organizations.ISPRIMARY, 1);
            getContentResolver().insert(workUri, values); 
jools
this will insert a new company. What I'm looking for is something which updates an exustung compnay details
frieza
Any way I found the answer myself. Thanks for all the help
frieza
frieza how did you solved this, im having the same problem?
mikedroid
A: 

Hi u write that u update number as well, that is good
i am able to update my contact display name but not able to update number how u can done it guide in this mater.

my effort is:

try{
    ContentValues valuesnumber = new  ContentValues();
    valuesnumber.put(android.provider.Contacts.Phones.NUMBER, "5559874");
    Uri contactUrinumber = Uri.withAppendedPath(People.CONTENT_URI,"2");
    Uri contactUrinumber1 = Uri.withAppendedPath(contactUrinumber, People.Phones.CONTENT_DIRECTORY);
    Log.d("path is", contactUrinumber.toString());
    getContentResolver().update(contactUrinumber, valuesnumber, null, null); 
    }catch (Exception e) {
        Log.d("Exception", e.getMessage());
    }

but it give me exception. java.lang.UnsupportedOperationException: Cannot update URL: content://contacts/people/2/phones

dhaiwat
there is an id associated with every phone-number. you need to append that id to your contactUrinumber1 uri and then make the update call
frieza