1. withvaluebackreference
Protected void createcontactentry () {arraylist <contentprovideroperation> Ops = new arraylist <contentprovideroperation> (); ops. add (contentprovideroperation. newinsert (contactscontract. rawcontacts. content_uri ). withvalue (contactscontract. rawcontacts. account_type, mselectedaccount. getType ()). withvalue (contactscontract. rawcontacts. account_name, mselectedaccount. getname ()). 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, "James "). 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, "10086 "). withvalue (contactscontract. commondatakinds. phone. type, "1 "). build (); ops. add (contentprovideroperation. newinsert (contactscontract. data. content_uri ). withvaluebackreference (contactscontract. data. raw_contact_id, 0 ). withvalue (contactscontract. data. mimetype, contactscontract. commondatakinds. email. content_item_type ). withvalue (contactscontract. commondatakinds. email. data, "google@sina.com "). withvalue (contactscontract. commondatakinds. email. type, "1 "). build (); try {getcontentresolver (). applybatch (contactscontract. authority, OPS);} catch (exception e) {log. E (TAG, "response toin encoutered while inserting contact:" + E );}}
Here withvaluebackreference ("column", "Index"); the first parameter corresponds to the column in the database, and the second parameter represents the value of the return. This is abstract, that is, index indicates the ID or number of results returned by the first few operations when you operate the database in batches.
For example, the above Code withvaluebackreference (contactscontract. Data. raw_contact_id, 0) indicates that the value of contactscontract. Data. raw_contact_id is set
ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType()) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName()) .build()
The id value of the URI after the insert operation is completed. Assume that the returned value is "content: // COM. android. contacts/raw_contacts/5 "here is the value of 5, here is the insert operation.
Of course, for the update operation, the returned result is the number of columns to be updated. The value of contactscontract. Data. raw_contact_id is the number of columns to be updated. ,
.. To be continued...