Not able to insert address of contacts in android

2019-08-26 02:43发布

问题:

I am able to insert new android contact's name, his all phone number and all email ids in android. But i am not able to insert his address. I tried it using following lines of codes, It did not show any error while inserting, but when i tried to open the contacts in Contacts list, it shows environment error for that contact.Please have a look at my code.

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                    .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.POBOX, poBox)
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.STREET, street)
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.REGION, state)
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city)
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, postalCode)  
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, country)
                    .withValue(ContactsContract.CommonDataKinds.StructuredPostal.TYPE, type)
                    .build());

Here poBox,street,state,city,postalCode,country ,type all are getting values.

回答1:

Your Mime type is wrong. It should be android.provider.ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE