How to update contact number using Android

Related searches

I am learning android. I am trying to upadate contact number programmatically. Could anyone help me please how can I do that.

My effort is:

String lNumber = pCur.getString( pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));   

ContentValues values = new ContentValues();

Uri lPhoneUri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, ContactsContract.CommonDataKinds.Phone.NUMBER);                      

values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, "45323333"));
getContentResover().update(lPhoneUri, values, ContactsContract.CommonDataKinds.Phone.NUMBER+"=?", new String[] { lNumber });        

I think you are pretty much there. The following uses the new API to update the WORK phone number of a contact, assume that that contact already has a work phone number.

public void updateContact (String contactId, String newNumber, Activity act) 
    throws RemoteException, OperationApplicationException{

        //ASSERT: @contactId alreay has a work phone number 
        ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
        String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + 
                        Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Phone.TYPE + "=?";
        String[] phoneArgs = new String[]{contactId, String.valueOf(Phone.TYPE_WORK)}; 
        ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
                .withSelection(selectPhone, phoneArgs)
                .withValue(Phone.NUMBER, newNumber)
                .build()); 
        act.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    }

How to update contact number using Android, Help people get in touch with you � On your Android phone or tablet, open your device's Settings app and then Google and then Manage your Google Account. Hi, What if contact has no WORK phone and we want to update the WORK phone number? – AndroidDev Mar 15 '13 at 9:51 I have the problem updating WORK phone if it is present then I can update it but there is problem when WORK phone is not there and I have to update it.


Try this

String where = ContactsContract.Data.DISPLAY_NAME + "=? AND " + 
    ContactsContract.Data.MIMETYPE + "=? AND " + 
    String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE) + "=?";

String[] params = new String[] {
    Cname,
    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
    String.valueOf(ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
};

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
    .withSelection(where, params)
    .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,"9999999999")
    // .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "Sample Name 21")
    .build()
);

//email
String where3 = ContactsContract.Data.DISPLAY_NAME + " = ? AND " + 
                                ContactsContract.Data.MIMETYPE + " = ?";

String[] params3 = new String[] {
    Cname,
    "vnd.android.cursor.item/email_v2"
};

ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
    .withSelection(where3, params3)
    .withValue(ContactsContract.CommonDataKinds.Email.DATA,"a@b.com")
    .build()
);

By using this I am able to update the contact details.

Change the phone number on your account & how it's used, Open the YouMail app and tap the Menu (☰) icon in the top left corner of the screen. Select Contacts and then select Everyone. Select the contact you would like to edit. Click the edit icon. Update the contact information here, then click Save when you are done. Edit your contact's number. Open your Android contacts app and edit the contact entry. Add the + and the country code to your contact's number. For numbers from Brazil, the number should start with +55 followed by the city code. For example, +55 21 (mobile number). For numbers from Argentina, the number should start with +549 followed by the


Just small change, if you need to update some other phone than work phone, you can have method that has this as a parameter.

public void updateContact (String contactId, String newNumber, String phoneType) 
throws RemoteException, OperationApplicationException{

    //ASSERT: @contactId alreay has a work phone number 
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
    String selectPhone = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + "='"  + 
                    Phone.CONTENT_ITEM_TYPE + "'" + " AND " + Phone.TYPE + "=?";
    String[] phoneArgs = new String[]{contactId, phoneType}; 
    ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
            .withSelection(selectPhone, phoneArgs)
            .withValue(Phone.NUMBER, newNumber)
            .build()); 
    this.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}

Modify contacts using intents, Inserting a contact using the contacts app inserts a new raw contact into the Contacts Provider's ContactsContract.RawContacts table. If necessary, the contacts app prompts users for the account type and account to use when creating the raw contact. The contacts app also notifies users if the raw contact already exists.


This class may help to update the contact.

public class UpdateContact extends Activity {

    private EditText txtName,txtPh;
    private Button btnUpdate;
    private TextView txt;
    private static final String TAG_ID="id";
    private static final String TAG_NAME = "name";
    private static final String TAG_PHNO = "phNo";
    private static int id;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_contact);
        txtName=(EditText)findViewById(R.id.txtNname);
        txtPh=(EditText)findViewById(R.id.txtNPhNo);
        btnUpdate=(Button)findViewById(R.id.btnUpdate);
        txt=(TextView)findViewById(R.id.txtId);

        Intent i=getIntent();
        id=i.getIntExtra(TAG_ID,0);
        txtName.setText(i.getStringExtra(TAG_NAME));
        txtPh.setText(i.getStringExtra(TAG_PHNO));
        //to update contact on button click you can apply this
        btnUpdate.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                DatabaseHandler handler=new DatabaseHandler(UpdateContact.this);
                Contact contact=new Contact();
                contact.setID(id);
                contact.setName(txtName.getText().toString());
                contact.setPhNo(txtPh.getText().toString());
                handler.UpdateContact(contact);
                finish();
            }
        });

    }  
}

Contacts Provider, We’re writing this guide using a Pixel 2 XL running Android 9.0, but it should look similar on other Android devices. We’re also using the stock Google Contacts apps, which you can download from the Play Store. These steps may not be the same on other Contact apps, so if you’re having issues, we recommend using Google Contacts.


Edit Your Contacts on Your Android – Help Center - Support, Add or change contact information. You’ll be able to edit the contact’s phone number, display name, email address, and various other options. Just tap the text field and type in the new information. To add another field (such as address, nickname, or relationship), scroll to the bottom of the contact and tap Add new field. Select the type


Call ContentResolver.update() method to update related contact info ( phone number ) in data table by raw contact id, data mimetype ( vnd.android.cursor.item/phone_v2 ) and data type ( Phone.TYPE_MOBILE ). These three column value can uniquely identify one contact data record in data table. /* * Update contact phone number by contact name.


Transfer contacts from Android to iPhone in 3 ways: Use Apple's Move to iOS app for Android, use a SIM card, or use Google. Some methods move more than contacts; if you only want contacts moved then go with the SIM card approach.