Points that are hard to understand in Android contacts applications

Source: Internet
Author: User

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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.