PDA

View Full Version : نمایش تصویر مخاطبین



beh3000
چهارشنبه 22 مهر 1394, 13:38 عصر
سلام


من برای گرفتن تصویر پروفایل مخاطبینم از کد زیر استفاده میکنم توی ایمولیتور تصویر پروفایل رو نشون میده ولی توی گوشی واقعی تست میکنم نشون نمیده چیزی




public void fetchContacts(final String number,final int position) {
Uri CONTENT_URI = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_UR I, Uri.encode(number));
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(CONTENT_URI, new String[]{ PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, null, null, null);
if (cursor.getCount() > 0)
{
cursor.moveToFirst();
long id = cursor.getLong(cursor.getColumnIndexOrThrow(PhoneL ookup._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(Phon eLookup.DISPLAY_NAME));
Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, id);
bmp= People.loadContactPhoto(ActivityMain.this, uri, R.drawable.profile, null);
}
}

hosseinaryai
پنج شنبه 23 مهر 1394, 06:49 صبح
من از متد زیر استفاده می کنم ، توی گوشی خودم که جواب میگیرم :



public static Bitmap getContactDisplayFacePhoto(Context context,String phoneNumber) {

Uri phoneUri = Uri.withAppendedPath
(ContactsContract
.PhoneLookup
.CONTENT_FILTER_URI,
Uri.encode(phoneNumber));
Uri photoUri = null;
ContentResolver cr = context.getContentResolver();
Cursor contact = cr.query(phoneUri,
new String[] { ContactsContract.Contacts._ID }, null, null, null);

if (contact.moveToFirst()) {
long userId = contact.getLong
(contact.getColumnIndex
(ContactsContract.Contacts._ID));
photoUri = ContentUris.withAppendedId
(ContactsContract.Contacts.CONTENT_URI, userId);

}
else {
//android.R.drawable.ic_menu_report_image
Bitmap defaultPhoto =
BitmapFactory.decodeResource
(context.getResources(),
R.drawable.ic_user);
return defaultPhoto;
}
if (photoUri != null) {
InputStream input =
ContactsContract
.Contacts
.openContactPhotoInputStream(
cr, photoUri);
if (input != null) {
return BitmapFactory.decodeStream(input);
}
} else {
//android.R.drawable.ic_menu_report_image
Bitmap defaultPhoto =
BitmapFactory.decodeResource
(context.getResources(),
R.drawable.ic_user);
return defaultPhoto;
}
//android.R.drawable.ic_menu_report_image
Bitmap defaultPhoto =
BitmapFactory.decodeResource
(context.getResources(),
R.drawable.ic_user);
return defaultPhoto;
}




اگه تو پروژه کپی کردی و اخطار داد داره یه عکس از پوشه ی drawable رو ایراد میگیره که به عنوان عکس پیش فرض انتخاب کنه.. یه عکس با همون نام توش پوشه drawable بذاری حل میشه