Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new contact via intent with multiple phone numbers

I want to add a new contact using ContactsContract.Intents.Insert. But the problem is that I don't know how many phone numbers can be. And as I understand I can pass only three phone numbers using PHONE, SECONDARY_PHONE, TERTIARY_PHONE constants. Is there any way to pass more than three numbers?

like image 900
Ov3r1oad Avatar asked Apr 09 '14 12:04

Ov3r1oad


Video Answer


1 Answers

Found a solution. It consists in using ContentValues:

    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    ArrayList<ContentValues> data = new ArrayList<ContentValues>();
    
    // Filling data with phone numbers
    for (int i = 0; i < numberOfPhones; i++) {
        ContentValues row = new ContentValues();
        row.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
        row.put(Phone.NUMBER, PhonesNumberList.get(i));
        // Setting the type of this phone number to be of Phone.TYPE_WORK
        row.put(Phone.TYPE, Phone.TYPE_WORK);
        data.add(row);
    }
    
    intent.putExtra(ContactsContract.Intents.Insert.NAME, mName);
    intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);
    startActivity(contactIntent);
like image 168
Ov3r1oad Avatar answered Sep 17 '22 17:09

Ov3r1oad