I need to get the number of events on the calendars for today. Only the number of events of all calendars, do not need anything more. I found several threads about it, but I can not get the number of events for today.
using this code, the variable "events" gives me the number of all events in the first calendar.
int events=0;
public void read() {
Context context = getApplicationContext();
ContentResolver contentResolver = context.getContentResolver();
long ntime = System.currentTimeMillis();
Cursor cursr = contentResolver.query(Uri.parse("content://com.android.calendar/events"), new String[]{ "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation" }, "calendar_id=1", null, null);
cursr.moveToFirst();
String[] CalNames = new String[cursr.getCount()];
int[] CalIds = new int[cursr.getCount()];
for (int i = 0; i < CalNames.length; i++) {
CalIds[i] = cursr.getInt(0);
CalNames[i] = "Event"+cursr.getInt(0)+": \nTitle: "+ cursr.getString(1)+"\nDescription: "+cursr.getString(2)+"\nStart Date: "+cursr.getLong(3)+"\nEnd Date : "+cursr.getLong(4)+"\nLocation : "+cursr.getString(5);
long StartTime = cursr.getLong(3);
long EndTime = cursr.getLong(4);
if ((StartTime<ntime)&&(ntime<EndTime)) {
System.out.println("In the middle of something");
break;
}
cursr.moveToNext();
events++;
}
cursr.close();
Log.i("control","vueltas:"+events);
events=0;
}
I need to modify the code to read events from all calendars of the device, and only events for today. several days looking for how to do it, but the solutions I've found (including this page) do not know how to apply my code... There is a very similar to my question, but has no answer https://mcmap.net/q/962155/-reading-all-of-today-39-s-events-using-calendarcontract-android-4-0
I appreciate your help.