0

There is a way to save the country name into a contact using Intent? Im trying with this code:

    Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
    intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
    intent.putExtra(ContactsContract.Intents.Insert.NAME, contactName);
    intent.putExtra(ContactsContract.Intents.Insert.NOTES, description);
    intent.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.CITY, contactTown);
    intent.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, contactCountry);
    intent.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.REGION, contactProvince);

But when i create a new contact, it comes without CITY, COUNTRY AND REGION

I appreciate any help!

Johan Sánchez
  • 165
  • 3
  • 17

1 Answers1

1

You have the POSTAL intent field for this, it's a free-format text field:

Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, contactName);
intent.putExtra(ContactsContract.Intents.Insert.NOTES, description);
intent.putExtra(ContactsContract.Intents.Insert.POSTAL, contactTown + ", " + contactCountry + " " + contactProvince);
intent.putExtra(ContactsContract.Intents.Insert.POSTAL_ISPRIMARY, true);
marmor
  • 27,641
  • 11
  • 107
  • 150