Not able to insert address of contacts in android

回眸只為那壹抹淺笑 提交于 2019-12-11 18:36:39

问题


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



来源:https://stackoverflow.com/questions/8286378/not-able-to-insert-address-of-contacts-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!