dropsOfJupiter dropsOfJupiter - 1 year ago 70
Android Question

android - get images from camera shot

I am curious as to how to get images from the Gallery/Camera folder in Android. I am looking into the file manager and can't really get a grasp as to where the those images are located in the file system. If I go to File Manager I can't locate the exact location of my taken photos. If I go to Gallery app I see them hanging in the "Camera" folder.

A little about what I am trying to accomplish:

Get all existing photos, saved at some point and display them on my activity. I am trying to allow the phone user to assign an avatar to their profile from existing photos.

Answer Source

here is the code, in case somebody needs it. This is tested on gingerbread.

List<Image> existingPhotos = getCameraImages(this);

            photosGrid = (GridView)findViewById(R.id.gvExistingPhotos);
            LazyPhotosGridAdapter adapter = new LazyPhotosGridAdapter(this, existingPhotos);

public String getRealPathFromURI(Uri contentUri) {
            String[] proj = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            return cursor.getString(column_index);

        public static List<Image> getCameraImages(Context context) {
            final String[] projection = { MediaStore.Images.Media.DATA };
            final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
            final String[] selectionArgs = { CAMERA_IMAGE_BUCKET_ID };
            final Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, 
            List<Image> result = new ArrayList<Image>(cursor.getCount());
            if (cursor.moveToFirst()) {
                final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                do {
                    final String data = cursor.getString(dataColumn);
                    result.add(new Image(data));
                } while (cursor.moveToNext());
            return result;

        public static final String CAMERA_IMAGE_BUCKET_NAME =
            + "/DCIM/Camera";
        public static final String CAMERA_IMAGE_BUCKET_ID =

         * Matches code in MediaProvider.computeBucketValues. Should be a common
         * function.
        public static String getBucketId(String path) {
            return String.valueOf(path.toLowerCase().hashCode());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download