android - How to fix disapearing of programmatically added SIM contacts after phone restart? -
using following code contact gets added sim on restart disappears. 1 more observation - before restart if edit sim contact(which added programmatically) android's contact app crashes contact gets edited , on restart remains not disappearing.
on devices other samsung not @ showing contacts in android's default contacts app. pulled contacts database , checked .. contains contacts have inserted programmatically. checked on lg optimus.
can other columns need consider or prob existing columns. in advance.
checked on samsung devices, europa, s3.
private void addsimcontacts() { // todo auto-generated method stub arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); int rawcontactinsertindex = ops.size(); ops.add(contentprovideroperation .newinsert(rawcontacts.content_uri) .withvalue(rawcontacts.account_type, new string("vnd.sec.contact.sim")) .withvalue(rawcontacts.account_name, new string("vnd.sec.contact.sim")) .withvalue(rawcontacts.source_id, new string("1")).build()); ops.add(contentprovideroperation .newinsert(contactscontract.data.content_uri) .withvaluebackreference(contactscontract.data.raw_contact_id, rawcontactinsertindex) .withvalue(data.mimetype, phone.content_item_type) .withvalue(phone.number, "9x-xxxxxxxxx").build()); ops.add(contentprovideroperation .newinsert(data.content_uri) .withvaluebackreference(data.raw_contact_id, rawcontactinsertindex) .withvalue(data.mimetype, structuredname.content_item_type) .withvalue(structuredname.display_name, "om").build()); try { contentproviderresult[] res = getcontentresolver().applybatch( contactscontract.authority, ops); } catch (remoteexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (operationapplicationexception e) { // todo auto-generated catch block e.printstacktrace(); } }
please find attached code snippet. has worked of cases.
void insertsimcontact() { uri simuri = uri.parse("content://icc/adn"); contentvalues values = new contentvalues(); string name[] = {"a", "b", "c", "d",}; int number[] = {1,2,3,4}; (int i=0; i<name.length; i++) { values.put("tag", name[i]); values.put("number", number[i]); getcontentresolver().insert(simuri, values); getcontentresolver().notifychange(simuri, null); } }
Comments
Post a Comment