[英]Get events from Google Calendar on Android
How can I get the list of events of a Calendar like this one https://twit.tv/schedule for a certain month? 如何获得某个月的日历事件列表,例如https://twit.tv/schedule ? Do I need to parse the HTML?
我需要解析HTML吗?
Edit: gooogle calendar specific link: https://calendar.google.com/calendar/embed?src=mg877fp19824mj30g497frm74o@group.calendar.google.com&ctz=GMT 编辑:gooogle日历特定链接: https ://calendar.google.com/calendar/embed?src=mg877fp19824mj30g497frm74o@group.calendar.google.com&ctz=GMT
AFAIK as you are trying to use it in Android and want to get the list of Calendar events you maybe should use the Calendar Provider 尝试在Android中使用AFAIK并想获取Calendar事件列表时,您可能应该使用Calendar Provider
https://developer.android.com/guide/topics/providers/calendar-provider.html https://developer.android.com/guide/topics/providers/calendar-provider.html
There's also a tutorial for Calendar API learning available 还提供了有关Calendar API学习的教程
https://developers.google.com/google-apps/calendar/quickstart/android https://developers.google.com/google-apps/calendar/quickstart/android
This post is a little bit old, but here is another easy solution for getting data related to Calendar content provider in Android: 这篇文章有点老了,但是这里是另一个简单的解决方案,用于获取与Android中的Calendar内容提供程序有关的数据:
Use this lib: https://github.com/EverythingMe/easy-content-providers 使用此库: https : //github.com/EverythingMe/easy-content-providers
Get all calendars: 获取所有日历:
CalendarProvider calendarProvider = new CalendarProvider(context);
List<Calendar> calendars = calendarProvider.getCalendars().getList();
Get all events : 获取所有事件:
List<Event> calendars = calendarProvider.getEvents(calendar.id).getList();
From the calendar provider doc , the following code will print the events from Sep 23, 2011 to Oct 24, 2011 在日历提供程序doc中 ,以下代码将打印2011年9月23日至2011年10月24日的事件
private static final String DEBUG_TAG = "MyActivity";
public static final String[] INSTANCE_PROJECTION = new String[] {
Instances.EVENT_ID, // 0
Instances.BEGIN, // 1
Instances.TITLE // 2
};
// The indices for the projection array above.
private static final int PROJECTION_ID_INDEX = 0;
private static final int PROJECTION_BEGIN_INDEX = 1;
private static final int PROJECTION_TITLE_INDEX = 2;
// Specify the date range you want to search for recurring
// event instances
Calendar beginTime = Calendar.getInstance();
beginTime.set(2011, 9, 23, 8, 0);
long startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2011, 10, 24, 8, 0);
long endMillis = endTime.getTimeInMillis();
Cursor cur = null;
ContentResolver cr = getContentResolver();
// The ID of the recurring event whose instances you are searching
// for in the Instances table
String selection = Instances.EVENT_ID + " = ?";
String[] selectionArgs = new String[] {"207"};
// Construct the query with the desired date range.
Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, startMillis);
ContentUris.appendId(builder, endMillis);
// Submit the query
cur = cr.query(builder.build(),
INSTANCE_PROJECTION,
null,
null,
null);
while (cur.moveToNext()) {
String title = null;
long eventID = 0;
long beginVal = 0;
// Get the field values
eventID = cur.getLong(PROJECTION_ID_INDEX);
beginVal = cur.getLong(PROJECTION_BEGIN_INDEX);
title = cur.getString(PROJECTION_TITLE_INDEX);
// Do something with the values.
Log.i(DEBUG_TAG, "Event: " + title);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(beginVal);
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Log.i(DEBUG_TAG, "Date: " + formatter.format(calendar.getTime()));
}
}
Or you can also use the Calendar API . 或者,您也可以使用Calendar API 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.