Hello there.
I want to make a custom widget with info about how many days remain to day when someone celebrate a birthday. It is possible to find out this info from Contacts?
Thanks. Juraj.
Contact info
Moderator: Martin
Re: Contact info
Hi,
There's no built-in action to query this information in a comfortable way so you have to use action Query Content Provider:
Content URI: content://comn.android.contacts/data
Projection: data1
Selection: display_name like 'NameXYZ%' and mimetype like '%event'
Result Type: Single value
Variable: birthdate
The date is provided as a text in format yyyy-MM-dd so you have to use a script to calculate the number of days to go. Following should work in an action Script:
Alternatively querying the contacts-calendar with condition Calendar Event could also work:
Starting: 30d before
Calendars: Google:Contacts
Event Type: All day events
Multiple events: Prefer the first
The start of the event will become available in variable event_start, title in variable event_title.
You still have to calculate the days to go using a script like the one shown above.
Regards,
Martin
There's no built-in action to query this information in a comfortable way so you have to use action Query Content Provider:
Content URI: content://comn.android.contacts/data
Projection: data1
Selection: display_name like 'NameXYZ%' and mimetype like '%event'
Result Type: Single value
Variable: birthdate
The date is provided as a text in format yyyy-MM-dd so you have to use a script to calculate the number of days to go. Following should work in an action Script:
Code: Select all
// adjust text to reflect birthday in current year, otherwise leap year might have negative effect
birthdate = "{trigertime,dateformat,yyyy}-"+substring(birthdate, 5);
// convert from text to a proper date object
date = getDate(birthdate, "yyyy-MM-dd");
// calculate the day number of birthday in this year
day_of_year = "{date,dateformat,D}";
// calculate todays day number
day_of_year_today = "{triggertime,dateformat,D}";
// calculate the day difference
diff = day_of_year - day_of_year_today;
Starting: 30d before
Calendars: Google:Contacts
Event Type: All day events
Multiple events: Prefer the first
The start of the event will become available in variable event_start, title in variable event_title.
You still have to calculate the days to go using a script like the one shown above.
Regards,
Martin