使用Google Calendar API V3解决了问题。我从这篇文章中找到的想法。假期可以从谷歌的默认假期日历中获取。
默认假期日历的ID列表可以在这里找到,支持40个国家。
一段处理权限并获取假期列表的代码:-
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();
}