1
我正在使用日曆協定從數據庫中提取事件。
首先,我得到日曆列表,然後在特定時間爲每個日曆提取所有事件,這一切都正常。我使用_id
列名來獲取事件ID。
但是,當我嘗試獲取待定事件以打開該特定事件上的日曆時,該日曆在另一個事件上打開。
我跑了一些測試,看看ID是否是唯一的,它看起來是正確的。
這裏是pendingIntent
的創建:從日曆協定事件ID啓動日曆到事件ID會打開錯誤事件
public static PendingIntent getEventPendingIntent(Context c, int eventID) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uri = Events.CONTENT_URI.buildUpon();
uri.appendPath(Long.toString(eventID));
intent.setData(uri.build());
return PendingIntent.getActivity(c, 0, intent, 0);
}
這是獲得一個給定CalendarID事件的方法:
private static Cursor getEvents(String calendarID, ContentResolver contentResolver, long timeFromNow) {
// Create a builder to define the time span
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
long now = new Date().getTime();
ContentUris.appendId(builder, now);
if (timeFromNow == -1) {
timeFromNow = DateUtils.DAY_IN_MILLIS * 10000;
}
ContentUris.appendId(builder, now + timeFromNow);
Cursor eventCursor = null;
// Create an event cursor to find all events in the calendar
String[] queryFields = {"title", "dtstart", "begin", "end", "allDay", "eventLocation","description", "_id" };
try {
eventCursor = contentResolver.query(builder.build(),
queryFields , "calendar_id=" + calendarID, null, "startDay ASC, startMinute ASC");
} catch (Exception e) {
Log.w(TAG, "ERROR: "+e.toString());
Log.w(TAG, "Didn't find calender for ID="+calendarID);
eventCursor = null;
}
return eventCursor;
}