如何获得选定国家的国家法定节假日国家、如何获得、法定节假日

2023-09-12 04:06:28 作者:心情好于坏,看的是女人。

我在做一个应用程序,可以从列表中选择国家。当选择一个国家,看来该国的国家法定节假日的列表。

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.

我见过的CalendarProvider和谷歌日历V3 。但它似乎只提供当前用户的日历。

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

更新:

我发现this帖子可以使用JSON获取列表的节日。在这个例子中,该国code。通过日历ID定义(pt_br.brazilian#holiday@group.v.calendar.google.com)  但我看不出有任何文档写这个。 我还发现了另外一个日历ID(en.usa#holiday@group.v.calendar.google.com)。

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).

时可以使用这种方式?如果是的话,我在哪里可以得到这些日历ID?

Is possible to use this way? If yes, where can I get those calendar id?

推荐答案

问题通过使用谷歌日历API V3 。我发现从想法this帖子。 这个节日可以从谷歌的默认假期日历。

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.

默认假期日历的ID列表,可以发现这里,为40个国家的支持。

The ID list of default holiday calendar can be found here, support to 40 country.

的code一个和平的处理权限,并得到节日列表:

A peace 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();
}