1

カレンダー コントラクトを使用して、DB からイベントを取得しています。
最初にカレンダーのリストを取得し、次に各カレンダーの特定の時間にすべてのイベントを取得すると、すべて正常に機能します。
列名を使用_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;
}
4

1 に答える 1

0

これを変更し_idevent_id
後、正しいイベントが表示されました。

于 2014-01-19T21:36:39.900 に答える