먼저 SD카드에 있는 그림 이미지를 넣는 것에 이어서 실제로 Content Provider, Gallery View 등을 사용하여 SD카드에 있는 그림을 화면에 표시하는 코드를 작성해보았습니다. 짧은 코드지만 이 안에서 사용되는 Adapter, Content Provider에 관한 것은 안드로이드의 데이터 처리에서 가장 기본적인 것입니다.

Content Provider에 관해서는 http://code.google.com/android/devel/data/contentproviders.html 에서 자세히 설명되어 있습니다.

Code

public class Photo extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Gallery gallery = (Gallery) findViewById(R.id.gallery);
        Cursor c = getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null); //Image데이터 쿼리
        ImageCursorAdapter adapter = new ImageCursorAdapter(this, c);
        gallery.setAdapter(adapter);        
    }
    
    class ImageCursorAdapter extends CursorAdapter {
     public ImageCursorAdapter(Context context, Cursor c) {
      super(context, c);
     }
     @Override
     public void bindView(View view, Context context, Cursor cursor) {
      ImageView img = (ImageView)view;
      
      long id = cursor.getLong(cursor.getColumnIndexOrThrow(Images.Media._ID));  
      Uri uri = ContentUris.withAppendedId(Images.Media.EXTERNAL_CONTENT_URI, id); //개별 이미지에 대한 URI 생성
      try {
          Bitmap bm = Images.Media.getBitmap(getContentResolver(), uri); //Bitmap 로드
          img.setImageBitmap(bm);
      } catch(Exception e) {} 
     }
     @Override
     public View newView(Context context, Cursor cursor, ViewGroup parent) {
      ImageView v = new ImageView(context);
      v.setLayoutParams(new Gallery.LayoutParams(80, 80)); 
      v.setScaleType(ImageView.ScaleType.FIT_CENTER);
      return v;
     }
    } 
}

Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Gallery android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        
        android:gravity="center_vertical"
        android:spacing="16dp"
        
    />    
</LinearLayout>

 덤으로 클릭시에 내장된 사진 뷰어를 뛰우려면

           Intent i = new Intent(Intent.ACTION_VIEW, uri);
           startActivity(i);
위와 같이 인텐트를 날리면 됩니다.