List all camera images in Android

How do you get a list of all camera images of an Android device?

Is it through the MediaStore? How?

  • How can I erase the old data from logcat?
  • How can I monitor another application's database for changes?
  • IntentRecieverLeakedException, Are you missing a call to unregisterReceiver() ? in android
  • Read speed of SharedPreferences
  • Android: Theme.Holo.Light.NoActionBar vs Theme.Light.NoTitleBar
  • ListView in ArrayAdapter order get's mixed up when scrolling
  • How to align the text inside the TextView in Android?
  • How the “FBReader” do the pagination of html files in epub
  • How to stop an android device from being charged programmatically?
  • Android - ActivityOptionsCompat - Custom Expand Animation
  • Is it essential to close the database?
  • Exclude specific build variants
  • One Solution collect form web for “List all camera images in Android”

    The Gallery app obtains camera images by using a content resolver over Images.Media.EXTERNAL_CONTENT_URI and filtering the results by Media.BUCKET_ID. The bucket identifier is determined with the following code:

    public static final String CAMERA_IMAGE_BUCKET_NAME =
            Environment.getExternalStorageDirectory().toString()
            + "/DCIM/Camera";
    public static final String CAMERA_IMAGE_BUCKET_ID =
            getBucketId(CAMERA_IMAGE_BUCKET_NAME);
    
    /**
     * Matches code in MediaProvider.computeBucketValues. Should be a common
     * function.
     */
    public static String getBucketId(String path) {
        return String.valueOf(path.toLowerCase().hashCode());
    }
    

    Based on that, here’s a snippet to get all camera images:

    public static List<String> 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, 
                projection, 
                selection, 
                selectionArgs, 
                null);
        ArrayList<String> result = new ArrayList<String>(cursor.getCount());
        if (cursor.moveToFirst()) {
            final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            do {
                final String data = cursor.getString(dataColumn);
                result.add(data);
            } while (cursor.moveToNext());
        }
        cursor.close();
        return result;
    }
    

    For more info, review the ImageManager and ImageList classes of the Gallery app source code.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.