To retrieve images from MediaStore during two separate time intervals in Android Studio, you can use the following steps:
Calendar interval1Start = Calendar.getInstance();
interval1Start.set(2021, Calendar.JANUARY, 1, 0, 0, 0);
Calendar interval1End = Calendar.getInstance();
interval1End.set(2021, Calendar.JUNE, 30, 23, 59, 59);
Calendar interval2Start = Calendar.getInstance();
interval2Start.set(2021, Calendar.JULY, 1, 0, 0, 0);
Calendar interval2End = Calendar.getInstance();
interval2End.set(2021, Calendar.DECEMBER, 31, 23, 59, 59);
long interval1StartMillis = interval1Start.getTimeInMillis();
long interval1EndMillis = interval1End.getTimeInMillis();
long interval2StartMillis = interval2Start.getTimeInMillis();
long interval2EndMillis = interval2End.getTimeInMillis();
// For interval 1
Cursor cursor1 = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null,
MediaStore.Images.Media.DATE_TAKEN + " >= ? AND " + MediaStore.Images.Media.DATE_TAKEN + " <= ?",
new String[]{String.valueOf(interval1StartMillis), String.valueOf(interval1EndMillis)},
MediaStore.Images.Media.DATE_TAKEN + " DESC"
);
// For interval 2
Cursor cursor2 = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null,
MediaStore.Images.Media.DATE_TAKEN + " >= ? AND " + MediaStore.Images.Media.DATE_TAKEN + " <= ?",
new String[]{String.valueOf(interval2StartMillis), String.valueOf(interval2EndMillis)},
MediaStore.Images.Media.DATE_TAKEN + " DESC"
);
if (cursor1 != null && cursor1.moveToFirst()) {
do {
String imageUri = cursor1.getString(cursor1.getColumnIndex(MediaStore.Images.Media.DATA));
// Do something with the image URI
} while (cursor1.moveToNext());
cursor1.close();
}
if (cursor2 != null && cursor2.moveToFirst()) {
do {
String imageUri = cursor2.getString(cursor2.getColumnIndex(MediaStore.Images.Media.DATA));
// Do something with the image URI
} while (cursor2.moveToNext());
cursor2.close();
}
Note: This code assumes that you have the necessary READEXTERNALSTORAGE permission in your AndroidManifest.xml file.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-13 02:21:02 +0000
Seen: 17 times
Last updated: Jun 13 '23
Is it possible for you to assist me with understanding the time complexity?
At compile time, how can I change a C string into an integer?
What is the process to activate the screen time off feature in Android using AOSP customization?
What is the meaning of charged_seconds and compute_seconds in Redshift serverless?
What are the steps for formatting time in various hh:mm:ss formats in Excel?
How to convert time differences between different time zones?