How to UPDATE contact phone number ?

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

How to UPDATE contact phone number ?

Postby AndreySerj » Fri Aug 07, 2009 11:15 am

Hi All,
I can create new contact and also add phone number (or email for example):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ...
  3.  
  4. ContentValues values = new ContentValues();
  5.  
  6. values.put(People.NAME, contact.getName());
  7.  
  8. Uri contactUri = activity.getContentResolver().insert(People.CONTENT_URI, values);
  9.  
  10.                        
  11.  
  12. Uri phoneUri = Uri.withAppendedPath(contactUri, People.Phones.CONTENT_DIRECTORY);
  13.  
  14. values.clear();
  15.  
  16. values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
  17.  
  18. values.put(People.Phones.NUMBER, contact.getPhoneNumber());
  19.  
  20. activity.getContentResolver().insert(phoneUri, values);
  21.  
  22. ...
  23.  
  24.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Then, I can update user name attribute (this step performs correctly):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ...
  3.  
  4. ContentValues values = new ContentValues();
  5.  
  6. values.put(People.NAME, contact.getName());
  7.  
  8. Uri contactUri = ContentUris.withAppendedId(People.CONTENT_URI, contact.getId());
  9.  
  10. activity.getContentResolver().update(contactUri, values, null, null);
  11.  
  12. ...
  13.  
  14.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But, when I am trying to update the phone number the same way ... I have exception: java.lang.UnsupportedOperationException: Cannot update URL: content://contacts/people/20/phones
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. ...
  3.  
  4. ContentValues values = new ContentValues();                    
  5.  
  6. values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
  7.  
  8. values.put(People.Phones.NUMBER, contact.getPhoneNumber());
  9.  
  10. Uri phoneUri = Uri.withAppendedPath(contactUri, People.Phones.CONTENT_DIRECTORY);
  11.  
  12. activity.getContentResolver().update(phoneUri, values, null, null);
  13.  
  14. ...
  15.  
  16.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Why ? What is wrong ?
AndreySerj
Developer
Developer
 
Posts: 31
Joined: Wed Dec 26, 2007 9:57 am
Location: Minsk

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 10 guests