我正在使用日历合同从数据库中提取事件
首先我得到一个日历列表,然后我在每个日历的特定时间内拉出所有事件,一切正常。
我使用_id
列名来获取事件ID
但是,当我尝试获取待处理事件以打开该特定事件的日历时,日历将在另一个事件中打开
我已经进行了一些测试,看看ID是否是唯一的,看起来是正确的
这是创建pendingIntent
:
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;
}
答案 0 :(得分:0)
问题在于ID列,我使用的是_id
而不是event_id
更改后,显示了正确的事件。