Retrieving Contact picture using Contact id
===

I am making an app. My first activity displays all contacts in a list view. If a contact is selected, it should launch another activity which displays the contact picture of the selected contact. But I don't understand how to retrieve the contact picture using contact id or display name. Please help

    package rocky.rakeshsarangi.app;

    import java.io.ByteArrayInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;

    import android.app.Activity;
    import android.app.ListActivity;
    import android.content.ContentResolver;
    import android.content.ContentUris;
    import android.content.res.AssetFileDescriptor;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.ContactsContract;
    import android.provider.ContactsContract.Contacts;
    import android.view.View;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;

    public class ContactsDB extends ListActivity
    {
	List<String> names = new ArrayList<String>(); // Stores all Contact names
	List<Integer> ids = new ArrayList<Integer>(); // Stores all Contact id's
	Bitmap photo; // For Contact Picture

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ContentResolver cr = getContentResolver();
		Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
				null, null, null);
		for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) // Moves       through all contacts
		{
			if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0)
			{	
				names.add(cur.getString(cur
						.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));  // Gets all Contact names
				ids.add(cur.getInt(cur.getColumnIndex(ContactsContract.Contacts._ID))); // Gets all Contact ids
			}

		}
		Collections.sort(names); // Sorts in alphabetical order
		setListAdapter(new ArrayAdapter<String>(ContactsDB.this,
				android.R.layout.simple_list_item_1, names)); // Displays in a list
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id)
	{
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		photo = BitmapFactory.decodeStream(getPhoto(position)); // Gets the contact picture of the selected contact
		
		
	}

	private FileInputStream getPhoto(int position) // Returns the contact picture of the selected contact
	{
		// TODO Auto-generated method stub
		 Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, ids.get(position));
	     Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
	     try {
	         AssetFileDescriptor fd =
	             getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
	         return fd.createInputStream();
	     } catch (IOException e) {
	         return null;
	     }
	}
    }
