Count calendar event?

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
schuster666
Posts: 52
Joined: 13 Nov 2013 14:03
Location: Germany / Neuss

Count calendar event?

Post by schuster666 » 11 Jun 2018 07:49

Hi there,
is it possible to count named calendar events (google calendar) for the actually year and for the rest of the year?

Thx
-- the world would be better without people--
-- but boring --

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Count calendar event?

Post by Desmanto » 12 Jun 2018 05:11

You can use Query Content Provider, it is in the example. But we have to modified it a bit to suit our need. First you have to specified the starting date and put the end of the year. Using action script.

Code: Select all

start = getDate();
year = "{start,dateformat,yyyy}";
endofyear = getDate(year, 12, 31, 23, 59,59);
Then use the {start} and {endofyear} as the variable in the URI.

Action Query Content Provider
Content URI : content://com.android.calendar/instances/when/{start}/{endofyear}
Projection : title
Result Type : List

The result is all events until end of year, in list {event_title}. Put condition debug dialog after it, to check if {event_title} contains exactly what you want.

If you need to count the number of the event, use

Code: Select all

count = length(event_title);
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
schuster666
Posts: 52
Joined: 13 Nov 2013 14:03
Location: Germany / Neuss

Re: Count calendar event?

Post by schuster666 » 12 Jun 2018 10:56

Hello, thanks for the answer.
On this way I have tried the last days too.
The problem is choosing the right calendar. If the search on all calendars is used I can not do anything with the results, because then, for example, "holiday" of all family members in the result is included.
I can not get a special calendar to query.

Is there a possibility?

Sorry that I was too inaccurate in the question.
-- the world would be better without people--
-- but boring --

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Count calendar event?

Post by Desmanto » 12 Jun 2018 16:48

Still can, but you need to figured out the difference first, between the event you need and the ones you don't. I don't know if it is the same in all android, as I almost never use calendar event (different people different need).

However the Projection field seems to have a bug. When you use custom variable as my first reply, I can't select the Projection anymore. It will give me error : Could not load column information.
So I have to revert to original and modify the value to approximately 1 year. Then load up all possible projection (just check all) and you will have all available calendar events
Content URI : content://com.android.calendar/instances/when/{triggertime}/{addDays(triggertime,300)}
Projection : just check all
Result Type : Table
Include header row : check

The result now, the event_titles contain all possible calendar event from current time till the next 300 days. It is in table format, with header; automagic see it as a list inside a list (nested list, 2 level).
You can put debug dialog after it and check the content of each row, spot the difference between the calendar event you want vs the ones you don't need.

But it is quite difficult to spot it, since there are so many data, there are 62 columns at mine. It will be easier if we check it at spreadsheet. We can then loop the list and join them with a tab (\t) and export it as list format.

Code: Select all

line = newList();
for(i in event_titles)
  addElement(line, join(i, "\t"));
write = "{line,listformat}";
The result is {write} , contain the all of the calendar events list in csv tab delimited format. You can then write this to file using Action Write to File, put {write} in the Text field, uncheck Append.

Send this csv.txt to your PC or any spreadsheet program and analyze the data. You can hide the column you don't need to make it faster. At mine, I can see it is the last column : calendar_displayName, which has the difference. At mine it will shown up as Hari libur di Indonesia. There are others simply shown up as Contacts, which contain my contact's birthday. So I know I can filter out the Hari libur di Indonesia using the calendar_displayName field.

Back to the Query Content Provider, we will project against the title again, but this time we filter out the information using the calendar_displayName.
Content URI : content://com.android.calendar/instances/when/{triggertime}/{addDays(triggertime,300)}
Projection : title
Selection : calendar_displayName = ?
Selection Arguments : Hari libur di Indonesia
Result Type : List

This time, it will show the title in list, but only from the arguments you specified in the calendar_displayName field.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply