【发布时间】:2016-08-02 07:18:14
【问题描述】:
在我的 android 应用中,我有代码来编写、更新和删除日历中的事件。
现在我想从日历中获取一些事件,但我不知道事件 ID。我想按标题、描述或任何其他值过滤事件。
我该怎么做?
我的代码:
public static void getEvents(Activity mContext) {
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
long now = new Date().getTime();
ContentUris.appendId(builder, now - DateUtils.DAY_IN_MILLIS * 10000);
ContentUris.appendId(builder, now + DateUtils.DAY_IN_MILLIS * 10000);
String selection = "((calendar_id = ?) AND (description LIKE ?))";
String[] selectionArgs = new String[] {""+id, "'%abc%'"};
Cursor eventCursor = contentResolver.query(builder.build(),
new String[] { "title", "begin", "end", "allDay", "description"},
selection, selectionArgs,
"startDay ASC, startMinute ASC");
while (eventCursor.moveToNext()) {
String eventTitle = eventCursor.getString(0);
String description = eventCursor.getString(4);
}
}
当我按日历 ID 仅过滤时 - 它可以工作,并且我会获得此日历中的所有事件。当我尝试添加“AND description = ?”时 - 我得到 0 个事件,尽管我知道它们的描述中有带有字符串的事件。
【问题讨论】:
标签: android google-calendar-api