How to add a phone number, email, website, etc. To existing contact

I am developing an application where I have to add a phone number, email address, website, address, etc. to an existing contact with the click of a button.

function at the touch of a button is here

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<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 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(); }}} 

I can’t update my contact.

+6
source share
1 answer

I assume that you do not know how to do this, and that is your question.

this can help

 ContentResolver cResolver = context.getContentResolver(); public void AddToContact() { insertContentValues(cResolver, Contacts.Phones.CONTENT_URI, getPhoneCV(phone)); } public ContentValues getPhoneCV(RowData data) { ContentValues cv = new ContentValues(); String PhoneNumber = "055434553"; cv.put(Contacts.Phones.NUMBER,PhoneNumber ); return cv; } private Uri insertContentValues(ContentResolver cResolver, Uri uri, ContentValues cv) { if (cv != null) { return cResolver.insert(uri, cv); } return null; } 
+1
source

Source: https://habr.com/ru/post/916893/


All Articles