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.
the function on the click of the button goes 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 am unable to update my contact.
At the bottom right, tap Add . Enter the contact’s name and an email or phone number. To pick the account where you want to save the contact: Next to your email account, tap the Down arrow . To add more name details: Next to "Name," tap the Down arrow .
When your old email address or phone number doesn't suit you anymore—but you want to retain your contacts, online storage, subscriptions, and settings—you can add a new email address or phone number as an alias to your existing Microsoft account. An alias is another email address or phone number that works with the same account.
Pressing on any unknown phone number in the list reveals a dropdown menu, where you can tap on the Add contact option. On some smartphones, like those from Huawei, press on the small i icon next to a number to reveal an option named Create New Contact. This opens the "Add to contacts" pane. Use it to add basic details to the number and press Save.
On some smartphones, like those from Huawei, press on the small i icon next to a number to reveal an option named Create New Contact. This opens the "Add to contacts" pane. Use it to add basic details to the number and press Save.
i am assuming that you do not know how to do that, and that is your question.
this may 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With