IMが動作するAPIは2.3であることに注意してください
デバイスの受信ボックスにテキストメッセージを送信した連絡先(現在は6人)が現在入力しているリストビューがあります。すべての連絡先が収集されてに渡されたArrayList<String>
後、ArrayListはCustomAdapterクラスのコンストラクターに渡されます。そこから、これは私のgetView()
メソッド内から私の受信トレイからの連絡先を私のリストビューに入力するコードです:
holder.photo = (ImageView) rowView.findViewById(R.id.iv_contactPic);
holder.contact = (TextView) rowView
.findViewById(R.id.contactEntryText);
String folder = "content://sms/inbox/";
Uri mSmsQueryUri = Uri.parse(folder);
contactID = new ArrayList<String>();
try {
c = context.getContentResolver().query(mSmsQueryUri,
new String[] { "_id", "address", "date", "body" },
null, null, null);
if (c == null) {
Log.i(TAG, "cursor is null. uri: " + mSmsQueryUri);
}
c.moveToFirst();
while (c.moveToNext()) {
cid = c.getString(0);
contactID.add(cid); // stores contact IDs
}
} catch (Exception e) {
//Log.e(TAG, e.getMessage());
} finally {
c.close();
}
if(holder != null){
holder.contact.setText(data.get(position)); // displays contact by name
//Contact photo not showing
holder.photo.setImageBitmap(getByteContactPhoto(contactID.get(position));
}
上記のコードから、holder.contact
問題なく6つの連絡先を表示します。しかし、問題はholder.photo
何も表示されないことです。写真を取得するための方法は次のとおりです。
public Bitmap getByteContactPhoto(String contactId) {
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(contactId));
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] {Contacts.Photo.DATA15}, null, null, null);
if (cursor == null) {
return null;
}
try {
cursor.moveToFirst();
if (cursor.moveToNext()) {
byte[] data = cursor.getBlob(0);
if (data != null) {
return BitmapFactory.decodeStream( new ByteArrayInputStream(data));
}
}
} finally {
cursor.close();
}
return null;
}
しかし、LogCatでは、これが写真を参照して表示される唯一のものです。
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
連絡先の写真が表示されるようにこれを修正するためのアイデアはありますか?