我试图显示联系人列表以及与其关联的照片,但是我看到大多数没有照片的联系人,虽然他们在我去手机的(SG2)默认联系人列表。我想这是因为其中一些联系人实际上是合并的,并且图片来自未在列表中显示的(原始?)联系人,所以问题是 - 我如何获得与给定联系人合并的所有联系人?我试着玩SQLite,但是我找不到任何能够唯一标识合并联系人的列。如何获取与给定联系人合并的所有联系人
从代码的角度来看,我开始与这个方法: 保护位图getImageByContactId(最终上下文appContext,最终字符串strContactId) { 位图bmContactImage = NULL;
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(strContactId));
Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
InputStream image = null;
try {
image = appContext.getContentResolver().openInputStream(photoUri);
bmContactImage = BitmapFactory.decodeStream(image);
try {
image.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
// This can be ignored because the Uri is generic and photo may not really exist
}
return bmContactImage;
}
但这只能返回相关的“原创”接触匹配原有的搜索条件的照片(在我的情况 - 接触ID) - 不若照片是相关联的链接到原始联系人的联系人。
我希望能做出类似下面的工作,如果我只能得到与原始联系人链接/关联/合并的联系人的(原始?)ID,但我似乎无法找到一种方法找到那些“其他”接触......
public static Bitmap loadContactPhoto(ContentResolver cr, long id) {
Uri uri = Uri.parse(String.format("content://com.android.contacts/contacts/%s", id));
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
if (input == null) {
return null;
}
return BitmapFactory.decodeStream(input);
}
底线 - 我想要做的是显示联系人的照片,无论是从搜索条件匹配的接触 - 或者任何的联系人与该联系人合并 - 任何解决方案将不胜感激!
谢谢!
如果你发布你的代码,它会更容易尝试和协助你... – Muzikant
添加代码 - 谢谢! –