我有一個listview
適配器和我想的newView
方法如下:如何獲得Android的聯繫縮略圖
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(layout, parent, false);
long contactId = Long.valueOf(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
boolean hasPhone = Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)));
String thumbnailUri = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI));
TextView name_text = (TextView) v.findViewById(R.id.name_entry);
if (name_text != null) {
name_text.setText(contactName);
}
name_text.setTag(new Contact(contactId, hasPhone));
ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail);
if (thumbnailUri != null) {
thumbnail.setImageURI(Uri.parse(thumbnailUri));
} else {
thumbnail.setImageResource(R.drawable.ic_launcher);
}
return v;
}
但是,當我嘗試解析存儲在thumbnailUri開放的,我收到了出現以下錯誤:
08-09 01:58:38.619: I/System.out(1471): resolveUri failed on bad bitmap uri: content://com.android.contacts/contacts/1/photo
我該怎麼做呢?任何幫助將不勝感激!
你可以在那裏放一個logcat信息來看看你想要解析的URI是什麼,並在這裏發佈? Log.i(「URI」,thumbnailUri); – RyanInBinary 2012-08-08 14:18:02
內容://com.android.contacts/contacts/1/photo,我相信這是正確的。也許這只是因爲我在使用模擬器。我需要一個真正的設備:/ – 2012-08-09 07:47:26
只需要一個真正的設備。這工作,我的代碼是好的。 – 2012-08-09 10:53:18