Skip to content Skip to sidebar Skip to footer

How To Add Postal Address To Contacts In Android Programmaticaly?

I am developing app which add contact info to android contact list .to How to add postal address to contacts in android programmatically ?

Solution 1:

It's been a while that this has been asked but maybe someone else is still interested in it. How to add a contact with address info:

importstatic android.provider.ContactsContract.Data;
importstatic android.provider.ContactsContract.Intents.Insert;

privatevoidcreateContactIntent() {
    IntentcontactIntent=newIntent(ContactsContract.Intents.Insert.ACTION, ContactsContract.Contacts.CONTENT_URI);
    contactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
    contactIntent.putExtra(Insert.NAME, "Sergio Mendes");
    contactIntent.putExtra(Insert.COMPANY, "Company One");
    contactIntent.putExtra(Insert.POSTAL, "Street 1, 9999 City, Country");
    contactIntent.putExtra(Data.IS_SUPER_PRIMARY, 1);
    startActivity(contactIntent);
}

Note that some devices like Samsung S5 / A5 will put the whole address into the "street" field. If you have any optimizations for this let me know.

Solution 2:

Postal address are stored like all the other info in the DATA table with a

MIMEtype == ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE

Please google ContactsContract.CommonDataKinds.StructuredPostalto find all the info.

If you need to know how to edit a contact in general I would suggest you to have a look to the SampleSyncAdapter in the Android SDK. It is a sync adapter so you don't need to study everything but updateContact in ContactManager is a good point to start with.

Post a Comment for "How To Add Postal Address To Contacts In Android Programmaticaly?"