1

Based on "Modifying Contacts Using Intents" (Android developer documentation) and the answer to "Start add new contact activity and pass structured data", I've devised a way of populating the Android contact picker with data to be edited and saved by the user.

I also have a comparable "headless" method using ContentProviderOperation, which works as intended for all contact fields I've tried (name, phone number, e-mail, structured address etc.).

However, when using the intent, somehow the structured address gets discarded and does not appear in the contact picker. A website URL added with the same method works fine.

This is my code, somewhat condensed:

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);

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

ContentValues addressRow = new ContentValues();
addressRow.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);

// The string values are prepared earlier, and I check that none of them is null.
// The ContentProviderOperation way doesn't seem to mind nulls, however.
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.STREET, street);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.POBOX, pobox);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.NEIGHBORHOOD, neighborhood);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.REGION, region);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, postcode);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, country);
addressRow.put(ContactsContract.CommonDataKinds.StructuredPostal.TYPE, addressType);
data.add(addressRow);

// This website address is shown in the contact edit screen, as expected:
ContentValues urlRow = new ContentValues();
urlRow.put(Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE);
urlRow.put(ContactsContract.CommonDataKinds.Website.URL, urlValue);
data.add(urlRow);

intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);

startActivityForResult(intent, ADD_CONTACT_REQUEST);  // my own request code

Please note that using an intent and using a ContentProviderOperation are different ways of achieving the same thing, both appropriate for their respective scenarios. My question is about the intent, so the answers to the following SO questions were not too helpful:

Any suggestions as to what I'm messing up here?

Community
  • 1
  • 1
Jere Käpyaho
  • 1,305
  • 1
  • 10
  • 29
  • I too was facing this issue. Here's where I found the solution: [Link](https://stackoverflow.com/a/16099965/5370523) – RSPL Oct 13 '17 at 10:46

0 Answers0