これを行うには、universalimageloaderを使用できますhttps://github.com/nostra13/Android-Universal-Image-Loader
以下の例を見ると、連絡先の写真をSDカートに保存してから、FilePathをリストに入れ、ユニバーサルイメージローダーでそのパスを使用できます。
https://dl.dropbox.com/u/68130108/UniversalImageLoaderExample.rarから完全な例をとることができます
アダプターgetViewで
imageLoader.displayImage(contactFilePath, holder.image, displayImageOptions);
アクティビティのパブリッククラスImageListActivityはBaseActivityを拡張します{AdapterContactadapterContact; DisplayImageOptionsオプション; String [] imageUrls; ArrayList contactList = new ArrayList(); ListView listView; ProgressDialogダイアログ; @Override public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState); setContentView(R.layout.ac_image_list);
listView = (ListView) findViewById(android.R.id.list);
new asynGetContacts().execute();
}
protected class asynGetContacts extends AsyncTask<String, Void, Integer> {
protected Integer doInBackground(String... params) {
try {
ImageListActivity.this.runOnUiThread(new Runnable() {
public void run() {
dialog = ProgressDialog.show(ImageListActivity.this, "","Lütfen bekleyin...", true);
dialog.show();
}
});
Uri uri = ContactsContract.Contacts.CONTENT_URI;
ContentResolver cr = getContentResolver();
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
Cursor cur = cr.query(uri, null, null, null, sortOrder);
if (cur.getCount() > 0) {
String id;
String name;
while (cur.moveToNext()) {
Contact c = new Contact();
id = cur.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Uri my_contact_Uri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_URI,
String.valueOf(id));
InputStream inputStream = ContactsContract.Contacts
.openContactPhotoInputStream(getContentResolver(),
my_contact_Uri);
BufferedInputStream buf = new BufferedInputStream(inputStream);
Bitmap my_btmp = BitmapFactory.decodeStream(buf);
if (my_btmp != null) {
c.photo = my_btmp;
c.id = id;
c.name = name;
c.photoURL = saveToSD(my_btmp, id);
contactList.add(c);
}
}
}
cur.close();
} catch (Exception e) {
Log.v("hata", e.toString());
return 0;
}
return 1;
}
protected void onPostExecute(Integer result) {
try {
dialog.dismiss();
adapterContact = new AdapterContact(ImageListActivity.this, 0,
contactList);
listView.setAdapter(adapterContact);
listView.setOnScrollListener(new PauseOnScrollListener(false, true));
} catch (Exception e) {
Log.v("hata", e.toString());
}
super.onPostExecute(result);
}
}
public String saveToSD(Bitmap bmp, String id) {
String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ContactImage/";
try {
File dir = new File(file_path);
if (!dir.exists())
dir.mkdirs();
File f = getFileStreamPath(file_path);
if (!f.exists()) {
File file = new File(dir, "contact_" + id + ".png");
FileOutputStream fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
}
} catch (Exception e) {
Log.v("Hata", e.toString());
}
return "file://"+file_path+"contact_" + id + ".png";
}
}