android - How to only update contacts instead adding in sync adapter -
i have few numbers stored in apps database. wanted match numbers in contacts app , update contact mimetype. how whatsapp does. sync contacts , app icon comes in contact.
i have done sync part , if add new contact able show app icon in contact . requirement update existing contact.
this have tried update contact,
arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(data.content_uri, true)) .withvaluebackreference(data.raw_contact_id,id) .withvalue(data.mimetype, mimetype) .withvalue(data.data1, "username") .withvalue(data.data2, "ite's me") .build()); try { context.getcontentresolver().applybatch(contactscontract.authority, ops); } catch (exception e) { e.printstacktrace(); }
and rawcontactid
fetching
cursor cursor = context.getcontentresolver().query(data.content_uri, new string[] {data.raw_contact_id, data.display_name, data.mimetype, data.contact_id }, contactscontract.commondatakinds.phone.number + "= ?", new string[] {phonenumb}, null);
i not able add connections contact. doing wrong. can please me this.
thanks in advance.
the problem you're using withvaluebackreference
reference raw contact id. try id of raw contact using parameter index previous operation in batch, i.e. if id=0, refer first operation, , if insert of new raw contact, use generated id raw contact id insert of contact data. want use withvalue
here, since have raw contact id.
Comments
Post a Comment