Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add phone no, email, website etc to existing contact [closed]

Tags:

android

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.

like image 480
Sagar Patil Avatar asked May 29 '12 09:05

Sagar Patil


People also ask

How do I add a contact to my account?

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 .

Can I add a new email address or phone number?

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.

How do I add a contact to an unknown phone number?

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.

How do I create a new contact on my phone?

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.


1 Answers

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;
    }
like image 134
AnasBakez Avatar answered Sep 28 '22 08:09

AnasBakez