Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get national holidays of selected country

I'm writing an app that allows the user to select a country from a list. When they pick a country, a list of national holidays of that country appears.

I've seen CalendarProvider and Google Calendar V3, but they seem to only provide the current user's calendar.

How can I get the national holidays of a specific country? Any suggestion would help me.


Update:

I've found this post which can get a list of holidays in JSON format. In this example, the country code is defined by calendar ID, for instance pt_br.brazilian#[email protected] or en.usa#[email protected].

But I can't find any documentation about this. Is it possible to use the API this way? If yes, where can I get those calendar IDs?

like image 438
Tai Dao Avatar asked Sep 25 '13 05:09

Tai Dao


People also ask

How do I change country calendar holidays?

To add or change the national holidays you see on your calendar: Open the Google Calendar app. In the top left, touch the Menu icon > Settings > Holidays. Touch the name of the current country.

Which country has the best national holidays?

Iran tops the ranking. Azerbaijan, Bulgaria and Malaysia share the second place with 19 paid public holidays.


2 Answers

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#[email protected]").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();
}
like image 85
Tai Dao Avatar answered Oct 05 '22 00:10

Tai Dao


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.

like image 28
ashatte Avatar answered Oct 05 '22 00:10

ashatte