Reputation: 224
I want to get the last taken image from the Camera folder. I don't want to get last screenshot or anything else. I just want to take the last image of the Camera folder.
This code works, but if there is a folder named "Cameras" or "xxx..Camera..xxx", the program also fetches the data of those folders.
cursor = MainActivity.this.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null,
MediaStore.Images.Media.DATA + " like ? ",
new String[] {"%Camera%"},
MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
But I don't want to query the folders whose name contains the "Camera" character sequence. I just want to query for Camera default save folder. In my case /storage/emulated/0/DCIM/Camera.
Upvotes: 1
Views: 801
Reputation: 224
I can query for specific directory by using
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
Now my code works like this and without any problems:
cursor = MainActivity.this.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " = ? ",
new String[] {"Camera"},
MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
Upvotes: 2