android - New contacts created using ContactsContract do not appear in Contacts app -
i'm using following piece of codes create new contact. follow closely contactmanager example provided android. problem is, created contacts not appear in contacts app shipped android. nevertheless, when load contacts phonebook, can see newly created contacts.
private void insertpbentry() throws remoteexception, operationapplicationexception {
arraylist<contentprovideroperation> ops = new arraylist<contentprovideroperation>(); ops.add(contentprovideroperation.newinsert(contactscontract.rawcontacts.content_uri) .withvalue(contactscontract.rawcontacts.account_type, "account type") .withvalue(contactscontract.rawcontacts.account_name, "account name") .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, "total_new") .build()); 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, "9090") .withvalue(contactscontract.commondatakinds.phone.type,phone.type_mobile) .build()); getcontentresolver().applybatch(contactscontract.authority, ops); }
i've searched hard have yet find answer. found 1 answer suggesting problem might have (sth) strings "account type" , "account name". case, not need create account whatsoever. want add new contact name, email/mail address, phones.
thanks, guys!
the sample codes provided google work. when it's run on emulator, no account or group can found attach created contact to. , default, newly created contact not visible.
using actual phone (for case, htc dream), after detecting account name , type feed in codes, works. alternatively, can visible group ids available , attach new contact 1 of groups.
to available accounts:
//accounts account[] accounts = accountmanager.get(act).getaccounts(); (account acc : accounts){ log.d(tag, "account name = " + acc.name + ", type = " + acc.type); }
to list of groups:
//group membership info string[] tempfields = new string[] { groupmembership.group_row_id, groupmembership.group_source_id}; cursor tempcur = act.managedquery(data.content_uri, tempfields, data.mimetype + "='" + groupmembership.content_item_type + "'", null, null);
now, if want associate new contact group instead of account:
ops.add(contentprovideroperation.newinsert(data.content_uri) .withvaluebackreference(data.raw_contact_id, 0) .withvalue(contactscontract.data.mimetype, groupmembership.content_item_type) .withvalue(groupmembership.group_source_id, *<the_identified_group_id>*) .build());
hope helps.
Comments
Post a Comment