How does android obtain the source image of the local address book?
When talking about the contact in the previous articles, all the headers obtained are stored in the database:
cursor = context.getContentResolver().query( ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photoId), new String[] { Photo.PHOTO }, null, null, null);
To obtain
In fact, if we add a library or a picture to a contact in the Local Address Book, the system will store the clear picture of the picture. If we want to get the picture, we need contactId.
getListView().setOnItemClickListener(new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView
parent, View view, int position, long id) {try {Cursor cursor = (Cursor) getListAdapter().getItem(position);if (cursor == 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 you want the image to have rounded corners, you can do this:
<frameLayout android:id="@+id/contacts_logo_layout" android:layout_width="@dimen/incall_photo_view_size" android:layout_height="@dimen/incall_photo_view_size" >
</frameLayout>
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.exe cute ();} private class loadTask extends AsyncTask
{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 ){
// This is the inputStream code that obtains the clear graph.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 ;}}
: