I'm making an app that can select country from a list. When pick a country, It appears a list of national holidays of that country.
I've seen CalendarProvider and Google Calendar V3. But It seem only provide current user calendar.
How to get national holidays as I want? Any suggestion also helped me
Update:
I've found this post which can get list holiday using json. In this example, the country code defined by calendar id (pt_br.brazilian#holiday@group.v.calendar.google.com)
But I don't see any docs write about this.
I also found another calendar id (en.usa#holiday@group.v.calendar.google.com).
Is possible to use this way? If yes, where can I get those calendar id?
Problem solved by using Google Calendar API V3. The idea I found from this post.
The holiday can get from default holiday calendar of google.
The ID list of default holiday calendar can be found here, support to 40 country.
A piece of code that handle permission and get holiday list:-
com.google.api.services.calendar.Calendar client = null;
credential = GoogleAccountCredential.usingOAuth2(mContext, CalendarScopes.CALENDAR);
credential.setSelectedAccountName(mList.get(0));
client = getCalendarService(credential);
do {
com.google.api.services.calendar.model.Events events;
events = client.events().list("en.usa#holiday@group.v.calendar.google.com").setPageToken(pageToken).execute();
onHolidayChecked(events.getItems()); //result return here (events.getItems())
pageToken = events.getNextPageToken();
} while (pageToken != null);
private com.google.api.services.calendar.Calendar getCalendarService(GoogleAccountCredential credential) {
return new com.google.api.services.calendar.Calendar.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
}
The CalendarProvider documentation states that it only provides the current user's calendar information.
The Calendar Provider is a repository for a user's calendar events.
The Calendar Provider API allows you to perform query, insert, update,
and delete operations on calendars, events, attendees, reminders, and
so on.
You will need to access a third-party API (this one, for example) and load that information into your application.