Reputation: 1103
Hi I have a problem in displaying the contacts image in android. Following is the code snippet I have used,
public String getCallersInfo(ContentResolver cnt,String phoneNumber)
{
mContentResolver = cnt;
lNumber = phoneNumber;
System.out.println("Start test");
Cursor l_Cur = mContentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.NUMBER +" = ?",
new String[]{lNumber }, null);
while (l_Cur.moveToNext())
{
cid = l_Cur.getString(l_Cur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
}
System.out.println("The contact ID for person with phone number "+ lNumber + " is " + cid);
if(!(cid.equals("Unknown")))
{
Cursor cursor_contacts = mContentResolver.query(ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts._ID + " = ?",
new String[]{cid },
null);
while(cursor_contacts.moveToNext())
{
displayname = cursor_contacts.getString(cursor_contacts.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME));
photoid = cursor_contacts.getString(cursor_contacts.getColumnIndex(
ContactsContract.Contacts.PHOTO_ID));
}
System.out.println("The display name & photo id for person with phone number "
+ lNumber + " is " + displayname + " & " + photoid);
Uri contactPhotoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Integer.parseInt(cid));
// Uri photoUri = Uri.withAppendedPath(contactPhotoUri, Contacts.Photo.CONTENT_DIRECTORY);
// contactPhotoUri --> content://com.android.contacts/contacts/1557
InputStream photoDataStream = Contacts.openContactPhotoInputStream(mContentResolver,contactPhotoUri); // <-- always null
if(photoDataStream == null)
{
System.out.println("No photo available ");
}
Bitmap bt = BitmapFactory.decodeStream(photoDataStream);
setmPhoto(bt);
}
return displayname;
}
Thanks in advance.
Upvotes: 0
Views: 632
Reputation: 4533
for the display image contact according to me u just do that i saw.. copy ur .png images res/drawable/a_1;
and write this where u want to see this image.. View v1=findViewById(R.drawable.a_1);
Upvotes: 1