
i want android apps connection added in contact. check whether user using app or not, based o result need add connection in existing contacts.
i have taken many reference adds new contact addition of connection. 1 of sample have used here
so can tell me procedure add account in existing contact?
i able create account visible in setting menu of phone.
i use tutorial 1 change have make in addcontact()
in tutorial, preferring, have change following code.
addcontact()deletes contacts has account type of package, have add more conditions of deleting particular contact.you have add details has added in existing contact in want add account contact number or email or name etc.
public static void addcontact(context context, mycontact contact) { contentresolver resolver = context.getcontentresolver(); // add condition want check string where= rawcontacts.account_type + " = ? , " +rawcontacts.display_name_primary+"=?"; //values of condotion string[] value=new string[] { accountgeneral.account_type ,contact.name}; resolver.delete(rawcontacts.content_uri, where, value); arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(rawcontacts.content_uri, true)) .withvalue(rawcontacts.account_name, accountgeneral.account_name) .withvalue(rawcontacts.account_type, accountgeneral.account_type) //.withvalue(rawcontacts.source_id, 12345) //.withvalue(rawcontacts.aggregation_mode, rawcontacts.aggregation_mode_disabled) .build()); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(settings.content_uri, true)) .withvalue(rawcontacts.account_name, accountgeneral.account_name) .withvalue(rawcontacts.account_type, accountgeneral.account_type) .withvalue(settings.ungrouped_visible, 1) .build()); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(data.content_uri, true)) .withvaluebackreference(data.raw_contact_id, 0) .withvalue(data.mimetype, structuredname.content_item_type) .withvalue(structuredname.given_name, contact.name) .withvalue(structuredname.family_name, contact.lastname) .build()); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(data.content_uri, true)) .withvaluebackreference(data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype,contactscontract.commondatakinds.phone.content_item_type) .withvalue(contactscontract.commondatakinds.phone.number, "12342145") .build()); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(data.content_uri, true)) .withvaluebackreference(data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype, contactscontract.commondatakinds.email.content_item_type) .withvalue(contactscontract.commondatakinds.email.data, "sample@email.com") .build()); ops.add(contentprovideroperation.newinsert(addcallerissyncadapterparameter(data.content_uri, true)) .withvaluebackreference(data.raw_contact_id, 0) .withvalue(data.mimetype, mimetype) .withvalue(data.data1, 12345) .withvalue(data.data2, "sample") .withvalue(data.data3, "sample") .build()); try { contentproviderresult[] results = resolver.applybatch(contactscontract.authority, ops); i++; if (results.length == 0) ; } catch (exception e) { e.printstacktrace(); } }
Comments
Post a Comment