This simple example gets the image from contacts in android.

private void getContactsDetails() {

		Cursor phones = getContentResolver().query(
				ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
				null, null);
		while (phones.moveToNext()) {
			String Name = phones
					.getString(phones
							.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
			String Number = phones
					.getString(phones
							.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

			String image_uri = phones
					.getString(phones
							.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));

			System.out.println("Contact1 : " + Name + ", Number " + Number
					+ ", image_uri " + image_uri);
 
			
			if (image_uri != null) {
			     image.setImageURI(Uri.parse(image_uri));
		        }
			

		}

Please leave your valuable comments.

 

3 Comments

  1. Nauman Zubair February 5, 2013 at 2:31 pm

    Hi, I tried your code but no image displayed. Can you tell me how to display facebook contact images in android listview.

     
    • James February 6, 2013 at 11:03 am

      Check whether your image is null or not in the Logcat.

       
  2. syam October 9, 2013 at 8:21 am

    in gingerbread contact image is crashing .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI))

     

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.