Question

(code segment revised - now working)

According to the Android references http://developer.android.com/reference/android/provider/ContactsContract.Intents.Insert.html it should be possible to pass an array of emails and phone numbers to the contact editor. Any one have success with this?

After a lot of research and experiments, nothing seems to work - it just ignores the parameters, as is evident by the editor opening with only the name field filled. This is on a Nexus 7 running Android 4.2.1. The Contacts app is version 4.2.1-533553.

Here's my code ("form" is declared and filled elsewhere):

Intent intent = new Intent();
intent.setAction (Intent.ACTION_INSERT);
intent.setData (ContactsContract.Contacts.CONTENT_URI);
intent.putExtra (ContactsContract.Intents.Insert.NAME, form.name);

ArrayList<ContentValues> parcels = new ArrayList<ContentValues>();

for (int i = 0;  i < form.phones.length;  i++)
{
  ContentValues row = new ContentValues();
  row.put (Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
  row.put (CommonDataKinds.Phone.NUMBER, form.phones[i]);
  row.put (CommonDataKinds.Phone.TYPE, form.phoneIds[i]);
  parcels.add (row);
}

for (int i = 0;  i < form.emails.length;  i++)
{
  ContentValues row = new ContentValues();
  row.put (Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE);
  row.put (CommonDataKinds.Email.ADDRESS, form.emails[i]);
  row.put (CommonDataKinds.Email.TYPE, form.emailIds[i]);
  parcels.add (row);
}

intent.putParcelableArrayListExtra (ContactsContract.Intents.Insert.DATA, parcels);
startActivityForResult (intent, ACTIVITY_REQUEST_FULL_EDIT);
Was it helpful?

Solution

Did you try to add phones.add(row) and emails.add(row) each time you fill a row ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top