How to add postal address to contacts in android programmaticaly?

后端 未结 2 339
谎友^
谎友^ 2021-01-28 07:40

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

相关标签:
2条回答
  • 2021-01-28 07:52

    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.

    0 讨论(0)
  • 2021-01-28 08:00

    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:

    import static android.provider.ContactsContract.Data;
    import static android.provider.ContactsContract.Intents.Insert;
    
    private void createContactIntent() {
        Intent contactIntent = new Intent(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.

    0 讨论(0)
提交回复
热议问题