私のアンドロイドアプリでは、カレンダーからイベントを書き込んだり、更新したり、削除したりするコードがあります。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個のイベントが表示されます。