[Java]View Plaincopyprint?
- Get the intent in the middle of the image
- Ivshowimage = (ImageView) Findviewbyid (r.id.call_log_detail_contact_img);
- //Call phone number get avatar URI
- Uri urinumber2contacts = URI
- . Parse ("content://com.android.contacts/"
- + "data/phones/filter/" + strphonenumber);
- Cursor cursorcantacts = sapplication.nowsapplication
- . Getcontentresolver (). Query (urinumber2contacts, null, null,
- null, null );
- if (Cursorcantacts.getcount () > 0) { //If the cursor is not 0 Then there is an avatar, and the cursor points to the first record
- Cursorcantacts.movetofirst ();
- Long ContactID = Cursorcantacts.getlong (cursorcantacts
- . Getcolumnindex ("contact_id"));
- Uri uri = Contenturis.withappendedid (
- ContactsContract.Contacts.CONTENT_URI, ContactID);
- InputStream input = contactscontract.contacts
- . Opencontactphotoinputstream (
- Sapplication.nowsapplication
- . Getcontentresolver (), URI);
- Btcontactimage = Bitmapfactory.decodestream (input);
- LOG.I ("info", "bt======" + btcontactimage);
- Ivshowimage.setimagebitmap (Btcontactimage);
- } else {//great avatar Set default avatar
- Ivshowimage
- . Setimageresource (R.drawable.call_log_contact_image2);
- }
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