• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps help to implement a contact list

I want a help to implement a contact list that contains a thumbnail photo of the existing contact photo, Contact Name and imageView.

i try to implement it many time But I did not know how to do it :confused: ....


any help pls
 
Here you got some code to retrieve the Name and contact picture from the people in your phone book. To get more information from the contacts, see ContactsContract.Contacts | Android Developers

Code:
public void getContactsIdAndName()
    {
    	Log.d("ContactList", "Starting contacts retrieval\n----------\n");

    	try
    	{
    		Cursor contacts = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    		while (contacts.moveToNext())
    		{
    			String contactID = contacts.getString(contacts.getColumnIndex(ContactsContract.Contacts._ID));
    			String contactName = contacts.getString(contacts.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    			Bitmap photo = getContactPicture(contactID);
    			Log.d("ContactList", "Id: " + contactID + "\nName: " + contactName + "\nPicture present: " + (photo != null ? "true" : "false") + "\n");

    			Cursor phoneNumbers = getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + contactID, null, null);
    			while (phoneNumbers.moveToNext())
    			{
    				String number = phoneNumbers.getString(phoneNumbers.getColumnIndex(Phone.NUMBER));
    				String type = phoneNumbers.getString(phoneNumbers.getColumnIndex(Phone.TYPE));
    				if (number == null || number.equals(""))
    					continue;
    				else
    					Log.d("ContactList", type + ": " + number + "\n");
    			}
    			phoneNumbers.close();
    			Log.d("ContactList", "----------\n");
    		}
    		contacts.close();
    		Log.d("ContactList", "----------\n");
    	}
    	catch (Exception ex) { Log.e("ContactList", "getContactIdAndName()", ex); }
    }

    public Bitmap getContactPicture(String contactID)
    {
    	Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(contactID));
    	InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), uri);
    	Bitmap contactPhoto = BitmapFactory.decodeStream(input);
    	if (contactPhoto != null)
    		return contactPhoto;
    	else
    		return null;
    }
 
Back
Top Bottom