Thursday, September 29, 2011

[android-developers] Load Contact Image in Listview

Hello to all,

I am developing one demo application . In that application i am trying
to load contact photo using below function.

public static long getProfilepicture(Activity activity, String
address)
{
Uri personUri =
Uri.withAppendedPath(ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,
address);
Cursor phoneCursor =
activity.getContentResolver().query(personUri,projection, null, null,
null);

if (phoneCursor.moveToFirst())
{
int indexPersonId =
phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone._ID );
long personId = phoneCursor.getLong(indexPersonId);
phoneCursor.close();
// Uri uri =
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
personId);
return personId;
}
return 0;
}

public static Bitmap loadContactPhoto(ContentResolver cr, long id)
{
Uri uri =
ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
Log.i("---------------- Load Contact Photo",".."+uri);
InputStream input =
ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
if (input == null)
{
Log.i("---------------- Input is Null","..");
return null;
}
return BitmapFactory.decodeStream(input);
}

First function getProfilepicture return the id of the contact person
on based of mobile number. Second function loadContactPhoto return the
bitmap.

But the second function always return the null.Can anyone tell me what
is the problem ? Where i am wrong ?

Here i also mentioned the Uri from which function trying to
openContactPhotoInputStream.
content://com.android.contacts/contacts/32

Thanks in advance.

Regards,
Chiag raval.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate