如何获得选定国家的国家假日 [英] How to get national holidays of selected country

查看:176
本文介绍了如何获得选定国家的国家假日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个可以从列表中选择国家/地区的应用。当选择一个国家时,它出现一个国家的国家节假日的列表。

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 < a>和 Google日历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

更新:

ve找到此帖,可以使用json获取列表度假。在此示例中,由日历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?

推荐答案

使用 Google Calendar API V3 。我从此信息中发现的想法。
假日可以从google的默认假日日历获取。

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.

一段代码,用于处理权限并获取假日列表: -

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

这篇关于如何获得选定国家的国家假日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆