1
在我的Android應用程序中,我有用於編寫,更新和從日曆中刪除事件的代碼。從Google日曆獲取和過濾事件
現在我想從日曆中獲取一些事件,但我不知道事件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個事件,雖然我知道在他們的描述中有字符串的事件。