在Android日历实例中搜索

时间:2017-05-05 04:05:46

标签: android calendar

我想按标题或说明在Android日历API Instances表中搜索事件。但由于API,我无法从表中获取所有实例。 CalendarContract.InstancesCONTENT_SEARCH_URI。有人知道如何使用它吗?

1 个答案:

答案 0 :(得分:0)

以下是CONTENT_SEARCH_URI以及如何使用它。

CONTENT_SEARCH_URI = content://com.android.calendar/instances/search

如果要使用它,请添加3个参数:毫秒begin,毫秒end和字符串search

Uri.Builder builder = CalendarContract.Instances.CONTENT_SEARCH_URI.buildUpon();
builder.appendPath(Long.toString(startDate));
builder.appendPath(Long.toString(endDate));
builder.appendPath(searchString);
Uri uri = builder.build();

路径为content://com.android.calendar/instances/search/[your begin]/[your end]/[your search]

如果使用此Uri进行查询,Android会生成此SQL:

SELECT Instances._id AS _id, Instances.event_id AS event_id,
    title, description, eventLocation
FROM (Instances INNER JOIN view_events AS Events ON
        (Instances.event_id=Events._id))
    LEFT OUTER JOIN Attendees ON (Attendees.event_id=Events._id)
WHERE (begin<=? AND end>=?)
GROUP BY Instances._id
HAVING (title LIKE ? ESCAPE "#"
    OR description LIKE ? ESCAPE "#"
    OR eventLocation LIKE ? ESCAPE "#"
    OR group_concat(attendeeEmail) LIKE ? ESCAPE "#"
    OR group_concat(attendeeName) LIKE ? ESCAPE "#" )