您好 我在android中显示联系人图像时遇到问题。 以下是我使用的代码段
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;
}
提前致谢。
答案 0 :(得分:1)
根据我的显示图像联系我只是这样做,我看到.. 复制你的.png图像res / drawable / a_1;
并写下你想看到这张图片的地方.. 查看v1 = findViewById(R.drawable.a_1);