How to add postal address to contacts in android programmaticaly?

后端 未结 2 372
谎友^
谎友^ 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 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.

提交回复
热议问题