In the last few words of contact, the avatar is in the database, through:
cursor = Context.getcontentresolver (). Query ( contenturis.withappendedid (ContactsContract.Data.CONTENT_URI, photoid), new string[] {Photo.photo}, NULL, NULL, NULL);
To get
In fact, if we in the local address book, if a contact Gakou or take photos of the picture, then the system will be a clear picture of the image stored, if you want to take this picture, you need to ContactID
Getlistview (). Setonitemclicklistener (New Onitemclicklistener () {@Overridepublic void Onitemclick (adapterview<? > Parent, view view, int position, long id) {try {cursor cursor = (cursor) getlistadapter (). GetItem (position); if (curso r = = null) {return;} int contactId = Cursor.getint (personal.id_column_index); Intent Intent = new Intent (); Intent.setclass ( Contactslist.this, Contactdetail.class), Intent.putextra ("ContactId", contactId); startactivity (intent);} catch (Exception ex) {ex.printstacktrace ();}}});
If we want the picture to have rounded corners, this can be done:
<linearlayout android:layout_width= "Fill_parent" android:layout_height = "Fill_parent" android:gravity= "center" > <framelayout android:id= "@+id/contacts_lo Go_layout "android:layout_width=" @dimen/incall_photo_view_size "android:layout_height=" @dimen/incall _photo_view_size "> <imageview android:id=" @+id/contact_photo "Android:layo Ut_width= "@dimen/incall_photo_view_size" android:layout_height= "@dimen/incall_photo_view_size" /> <imageview android:id= "@+id/contacts_logoborder" android:layout_width = "@dimen/incall_photo_view_size" android:layout_height= "@dimen/incall_photo_view_size" Andro id:background= "@drawable/images_box" > </ImageView> </FrameLayout> </linear Layout>
Java code:
@Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (Window.feature_no_title); Setcontentview (r.layout.contact_detail); int contactId = GetIntent () . Getintextra ("ContactId", 0); Contact_photo = (ImageView) Findviewbyid (R.id.contact_photo); Loadtask task = new Loadtask (contactId); Task.execute ();} Private class Loadtask extends Asynctask<void, Void, bitmap>{public loadtask (int id) {contactId = ID;} private int contactId; @Overrideprotected Bitmap doinbackground (Void ... params) {InputStream InputStream = Opendisplayphoto (CONTACTID); Bitmapfactory.options opt = new bitmapfactory.options (); opt.insamplesize = 1; Bitmap Bitmap = Bitmapfactory.decodestream (InputStream, NULL, opt); return Bitmap;} @Overrideprotected void OnPostExecute (Bitmap result) {if (result! = null) {Contact_photo.setimagebitmap (result);} Super.onpostexecute (result);}} Public InputStream Opendisplayphoto (long contactId) {<strong>//This is the code that takes the InputStream of the clear diagram </strong> Uri Contacturi = Contenturis.withappendedid (Contacts.content_uri, contactId); Uri Displayphotouri = Uri.withappendedpath (Contacturi, Contacts.Photo.DISPLAY_PHOTO); try {assetfiledescriptor fd = This.getcontentresolver (). Openassetfiledescriptor (Displayphotouri, "R"); return Fd.createinputstream (); } catch (IOException e) {e.printstacktrace (); return null; } }
: