Some times there will be kind of requirement when you need to extract the images or the media files from the device. So here is a method you can use for fulfilling the same.
private void getImagesInDuration(String startDate, String endDate){
Date parsedStart = new Date();
Date parsedEnd = new Date();
try {
SimpleDateFormat format =
new SimpleDateFormat("MM-dd-yyyy h:mm a",Locale.getDefault());
parsedStart = format.parse(startDate);
parsedEnd = format.parse(endDate);
}
catch(ParseException pe) {
throw new IllegalArgumentException();
}
String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN};
String selection = MediaStore.Images.Media.DATE_TAKEN + " < ?";
String[] selectionArgs = { String.valueOf(parsedEnd) };
Cursor cursor = context.getContentResolver()
.query(Images.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
selectionArgs,
null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int dateColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN);
String date = cursor.getString(dateColumn);
if(Long.valueOf(date)<parsedEnd.getTime() && Long.valueOf(date)>parsedStart.getTime()){
imagePathList.add(cursor.getString(0));
}
}
}
cursor.close();
}
In the last you will find the the array list imagePathList which will be full of the image paths of the images present in that device, if it had any during that period. You just have to enter the start and end date as a parameter for this method.
It has worked for me hope it will do the same for you, also you can modify it according to your requirement.
If any assistance required just feel free to ask. :)
0 Comment(s)