Matt Wolfe
Matt Wolfe

Reputation: 9284

How to get all images on device (sdcard particularly) on android (2.1 or greater)

I've followed the tutorial here: http://androidsamples.blogspot.com/2009/06/how-to-display-thumbnails-of-images.html and also another one which has almost identical code, and I'm having some problems/inconsistencies in how images are processed on different devices.

My code for gathering the images is this:

private void init_phone_image_grid() {
    String[] img = { MediaStore.Images.Thumbnails._ID };
    Uri uri = MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI;
    imagecursor = managedQuery(uri, img, null,
            null, MediaStore.Images.Thumbnails.IMAGE_ID);
    image_column_index = imagecursor
            .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
    count = imagecursor.getCount();
    imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
    imagegrid.setAdapter(new ImageAdapter(getApplicationContext()));
    imagegrid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView parent, View v, int position,
                long id) {
            System.gc();
            String[] proj = { MediaStore.Images.Media.DATA };
            actualimagecursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
                    null, null, null);
            actual_image_column_index = actualimagecursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            actualimagecursor.moveToPosition(position);
            String i = actualimagecursor
                    .getString(actual_image_column_index);
            System.gc();
            Intent intent = new Intent(getApplicationContext(),
                    EvidenceImageView.class);
            intent.putExtra("filename", i);
            startActivity(intent);
        }
    });
}

I have an emulator running android 2.2 and was able to create an sdcard file to mount with it.. I copied some images into a folder using adb and restarted the emulator (my app didn't show any images at first).. After rebooting some of the images showed up in my app but not all.. Then after I open the Gallery application that comes with the emulator I was able to get my gallery to load all of the images just fine.. However I also have a HTC thunberbolt and i've got photos on it (under /sdcard/DCIM/100MEDIA) and it will not display any images at all in the same app (referring to the one I'm working on).. I do not have the phone hooked up to the computer so I know there is no problem with my phone being able to access the sdcard.. Also I've tried the gallery application that came with my phone and my photos/videos load just fine in that.. The application that comes with HTC phones is a bit different than the one that comes with vanilla android phones I believe.. This makes me wonder if the system isn't handing images the same way..

I am brand new to android development and was hoping this would be pretty simple.. I looked into some other apps, such as facebook, and it appears to take me directly into the gallery provided by htc when I want to upload a photo.. Perhaps I could take this same approach (not totally sure how).. Eventually I want the user to be able to select multiple images and upload all of them... I also found the source code for the Camera app that comes with android:

https://android.googlesource.com/platform/packages/apps/Camera/+/master/src/com/android/camera

This is somewhat useful but quite a bit of information to digest at this point.

Any explanations of "how this stuff works" would be great. The main thing though is, how do I get my gallery to show all of the thumbnail images (creating thumbnails if necessary).. Or, how can I interface with the system gallery..

Upvotes: 3

Views: 9662

Answers (1)

Jayy
Jayy

Reputation: 14728

it appears to take me directly into the gallery provided by htc when I want to upload a photo.. Perhaps I could take this same approach

What's wrong with this:

How to pick an image from gallery (SD Card) for my app?

Upvotes: 1

Related Questions