Android gets contact information by querying the phone number

Source: Internet
Author: User

[Java]View Plaincopyprint?
  1. Get the intent in the middle of the image
  2. Ivshowimage = (ImageView) Findviewbyid (r.id.call_log_detail_contact_img);
  3. //Call phone number get avatar URI
  4. Uri urinumber2contacts = URI
  5. . Parse ("content://com.android.contacts/"
  6. + "data/phones/filter/" + strphonenumber);
  7. Cursor cursorcantacts = sapplication.nowsapplication
  8. . Getcontentresolver (). Query (urinumber2contacts, null, null,
  9. null, null );
  10. if (Cursorcantacts.getcount () > 0) { //If the cursor is not 0 Then there is an avatar, and the cursor points to the first record
  11. Cursorcantacts.movetofirst ();
  12. Long ContactID = Cursorcantacts.getlong (cursorcantacts
  13. . Getcolumnindex ("contact_id"));
  14. Uri uri = Contenturis.withappendedid (
  15. ContactsContract.Contacts.CONTENT_URI, ContactID);
  16. InputStream input = contactscontract.contacts
  17. . Opencontactphotoinputstream (
  18. Sapplication.nowsapplication
  19. . Getcontentresolver (), URI);
  20. Btcontactimage = Bitmapfactory.decodestream (input);
  21. LOG.I ("info", "bt======" + btcontactimage);
  22. Ivshowimage.setimagebitmap (Btcontactimage);
  23. } else {//great avatar Set default avatar
  24. Ivshowimage
  25. . Setimageresource (R.drawable.call_log_contact_image2);
  26. }

Get contact URL Use the following, Xiaomi mobile phone will appear some mobile phone number can not get, the number if it is fixed (0208888888) also get the details of the problem:

Context.getcontentresolver (). Query (
Phone.content_uri,
Projection
Phone.number + "=" + telephonenumber + "'",
Null
NULL);

Android gets contact information by querying the phone number

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.