I am trying to get the last image captured by the user using a camera app using the following code and display it to the user in my camera app's (like other camera apps do, show a small preview of the last image capture in a corner):
String[] projection = new String[]{
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATA,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
MediaStore.Images.ImageColumns.DATE_TAKEN,
MediaStore.Images.ImageColumns.MIME_TYPE
};
final Cursor cursor = getContentResolver()
.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
if (cursor.moveToFirst()) {
Bitmap bm = BitmapFactory.decodeFile(cursor.getString(1));
imagePreview.setImageBitmap(bm);
}
but the code shows me the last image in my phone from anywhere, like if i take a screenshot then it shows me that. I want to display the last image captured from the DCIM folder or whichever folder the photos are kept, not photos I download or screenshot. Can anyone help me out?