Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add phone no, email, website etc to existing contact
    text
    copied!<p>I am developing an application where, I have to add phone no, email, website, address etc. to my existing contact on a click of a button.</p> <p>the function on the click of the button goes here</p> <pre><code>private void updateContact(String name) { Log.d(TAG, "in updatecontact()"); Log.d(TAG,"Contact name to be updated = "+name); ContentResolver cr = getContentResolver(); String where = ContactsContract.Data.DISPLAY_NAME + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ? AND " + String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE) + " = ? "; String[] params = new String[] {name, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_HOME)}; Cursor phoneCur = managedQuery(ContactsContract.Data.CONTENT_URI, null, where, params, null); ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;(); if ( (phoneCur == null) ) { add_new_contact(); } else { // Phone no ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) .withSelection(where, params) .withValue(ContactsContract.CommonDataKinds.Phone.DATA, Tel) .build()); // Email ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) .withSelection(where, params) .withValue(ContactsContract.CommonDataKinds.Email.DATA, Email) .build()); // Website ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) .withSelection(where, params) .withValue(ContactsContract.CommonDataKinds.Website.DATA, Url) .build()); //Organization ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) .withSelection(where, params) .withValue(ContactsContract.CommonDataKinds.Organization.DATA, Org) .build()); } phoneCur.close(); try { cr.applyBatch(ContactsContract.AUTHORITY, ops); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (OperationApplicationException e) { // TODO Auto-generated catch block e.printStackTrace(); }}} </code></pre> <p>I am unable to update my contact.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload