Insert contact programmatically in android 4.0 is not showing in default contact list -
i'm doing android application insert contacts programmatically.i've added 1 contact using below code. adding couldn't see contact on default device contact list. device version 4.0.4. showing & on other devices.thanks in advance.
code:
private void createcontact(string name, string phone) { contentresolver cr = getcontentresolver(); arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation .newinsert(contactscontract.rawcontacts.content_uri) .withvalue(contactscontract.rawcontacts.account_type, "accountname@gmail.com") .withvalue(contactscontract.rawcontacts.account_name, "com.google").build()); ops.add(contentprovideroperation .newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue( contactscontract.data.mimetype, contactscontract.commondatakinds.structuredname.content_item_type) .withvalue( contactscontract.commondatakinds.structuredname.display_name, name).build());// display name comes here ops.add(contentprovideroperation .newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, 0) .withvalue( contactscontract.data.mimetype, contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, phone)// phone number comes here .withvalue(contactscontract.commondatakinds.phone.type, contactscontract.commondatakinds.phone.type_home) .build()); try { cr.applybatch(contactscontract.authority, ops); } catch (remoteexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (operationapplicationexception e) { // todo auto-generated catch block e.printstacktrace(); } }
Comments
Post a Comment