Android Write contacts

Source: Internet
Author: User

  1. public void Testinsert () {
  2. Contentvalues values = new Contentvalues ();
  3. /*
  4. * First, a null value is inserted into the Rawcontacts.content_uri to obtain the Rawcontactid returned by the system
  5. */
  6. Uri Rawcontacturi = This.getcontext (). Getcontentresolver (). Insert (Rawcontacts.content_uri, values);
  7. Long Rawcontactid = Contenturis.parseid (Rawcontacturi);
  8. Writing name data to the data table
  9. Values.clear ();
  10. Values.put (data.raw_contact_id, Rawcontactid);
  11. Values.put (Data.mimetype, Structuredname.content_item_type); Content Type
  12. Values.put (Structuredname.given_name, "Li Tianshan");
  13. This.getcontext (). Getcontentresolver (). Insert (Android.provider.ContactsContract.Data.CONTENT_URI, values);
  14. Write phone data to the data table
  15. Values.clear ();
  16. Values.put (data.raw_contact_id, Rawcontactid);
  17. Values.put (Data.mimetype, Phone.content_item_type);
  18. Values.put (Phone.number, "13921009789");
  19. Values.put (Phone.type, phone.type_mobile);
  20. This.getcontext (). Getcontentresolver (). Insert (Android.provider.ContactsContract.Data.CONTENT_URI, values);
  21. Write the data of the email to the table
  22. Values.clear ();
  23. Values.put (data.raw_contact_id, Rawcontactid);
  24. Values.put (Data.mimetype, Email.content_item_type);
  25. Values.put (Email.data, "[Email protected]");
  26. Values.put (Email.type, email.type_work);
  27. This.getcontext (). Getcontentresolver (). Insert (Android.provider.ContactsContract.Data.CONTENT_URI, values);
  28. }

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.