tags:

views:

24

answers:

1

Hey Guys,

How would I edit this tutorial so that it will grab images from the SD card?

http://developer.android.com/guide/tutorials/views/hello-gallery.html

          private Integer[] mImageIds = {
        R.drawable.lol.marker,
        R.drawable.sample_2,
        R.drawable.sample_3,
        R.drawable.sample_4,
        R.drawable.sample_5,
        R.drawable.sample_6,
        R.drawable.sample_7
        };

Alternatively is it possible to make subfolders within R.drawable?

+1  A: 

R.drawable is not a directory but a class containing static fields which are references to your resources.You can't create subfolders in the directory "drawable".
Now If you want to replace this array of ids by images on the SD card, you have to use a content resolver to get them. Would be something like that I suppose :

Cursor c = this.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null,null);
startManagingCursor(c);  

and then when you have retrieved the id of the images you want, you can put them in the array and use something like that to display them :

yourImageView.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, id+"")); 

EDIT
You can try something like that. Though i'm not sure:

 Bitmap bitmap = BitmapFactory.decodeFile("path/to/the/image.png");
  yourImageView.setImageBitmap(bitmap);
Sephy
But how do I only take them from a specific folder on the SD card?
Ulkmun
Well, if you already know the location of the images you want to reach, you can try something like my edit.
Sephy