日历查询

发布于 2024-10-05 04:06:51 字数 2550 浏览 2 评论 0原文

我正在尝试构建一个查询以从本机日历中获取事件,我已存储了以下 3 个单词中的 1 个单词的描述:“google”、“yahoo”、“stackoverflow”

例如:description="google",

As现在,我已经做了如下查询:

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=" + calId,
        null, "startDay ASC, startMinute ASC"); 

现在,我想用描述部分进行查询,我该怎么办?我当前的实现是错误的,请告诉我正确的方法,就好像你知道一样!

更新:

到目前为止我已经完成了:

public String Fetch_Events_Detail(long From_milliseconds, String kind_website)
 {
  String event_detail = null;

  Uri.Builder builder = calendar_events_URI.buildUpon();
        //long now1 = new Date().getTime();
        ContentUris.appendId(builder, From_milliseconds);
        ContentUris.appendId(builder, From_milliseconds + DateUtils.DAY_IN_MILLIS);


       /* Cursor eventCursor = getContentResolver().query(builder.build(),
                new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=? and description = ?",
                new String[] { DatabaseUtils.sqlEscapeString(calId),  DatabaseUtils.sqlEscapeString(kind_website)}, "startDay ASC, startMinute ASC"); 
        */

        Cursor eventCursor = getContentResolver().query(builder.build(),
                new String[] {"event_id", "title", "begin", "end", "allDay","description" },"Calendars._id=" + calId,
                null, "startDay ASC, startMinute ASC"); 

        if(eventCursor != null)
        {

         while (eventCursor.moveToNext()) 
         {
            String uid2 = eventCursor.getString(0);
            String event_title = eventCursor.getString(1);
            String event_start = eventCursor.getString(2);
            String event_description = eventCursor.getString(5);

            try
            {
                // SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
             SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                Date resultdate = new Date(Long.parseLong(event_start));

                event_detail=sdf.format(resultdate)+"  "+event_title;
                event_detail.trim();

                if(event_description.trim().equalsIgnoreCase(kind_website))
                { 
                 return event_detail;
                }
            }
            catch(NumberFormatException e)
            {
             Log.i("Exception raised", "");
            }
          }
        }

        return null;
 }

Thanx

I am trying to build a query for fetching the events from the native calendar, i have stored description with 1 word from the these 3 words: "google", "yahoo", "stackoverflow"

For example: description="google",

As of now, i have made query as below:

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=" + calId,
        null, "startDay ASC, startMinute ASC"); 

now, i would like to make query with Description part, how do i?? of my current implementation is wrong, please show me a correct way as if you know !!!

Update:

I have done so far:

public String Fetch_Events_Detail(long From_milliseconds, String kind_website)
 {
  String event_detail = null;

  Uri.Builder builder = calendar_events_URI.buildUpon();
        //long now1 = new Date().getTime();
        ContentUris.appendId(builder, From_milliseconds);
        ContentUris.appendId(builder, From_milliseconds + DateUtils.DAY_IN_MILLIS);


       /* Cursor eventCursor = getContentResolver().query(builder.build(),
                new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=? and description = ?",
                new String[] { DatabaseUtils.sqlEscapeString(calId),  DatabaseUtils.sqlEscapeString(kind_website)}, "startDay ASC, startMinute ASC"); 
        */

        Cursor eventCursor = getContentResolver().query(builder.build(),
                new String[] {"event_id", "title", "begin", "end", "allDay","description" },"Calendars._id=" + calId,
                null, "startDay ASC, startMinute ASC"); 

        if(eventCursor != null)
        {

         while (eventCursor.moveToNext()) 
         {
            String uid2 = eventCursor.getString(0);
            String event_title = eventCursor.getString(1);
            String event_start = eventCursor.getString(2);
            String event_description = eventCursor.getString(5);

            try
            {
                // SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
             SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
                Date resultdate = new Date(Long.parseLong(event_start));

                event_detail=sdf.format(resultdate)+"  "+event_title;
                event_detail.trim();

                if(event_description.trim().equalsIgnoreCase(kind_website))
                { 
                 return event_detail;
                }
            }
            catch(NumberFormatException e)
            {
             Log.i("Exception raised", "");
            }
          }
        }

        return null;
 }

Thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独岁月 2024-10-12 04:06:51
Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=? and description = ?",
        new String[] { DatabaseUtils.sqlEscapeString(calId),  DatabaseUtils.sqlEscapeString(description)}, "startDay ASC, startMinute ASC"); 

不用 calId 试试这个

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "description = ?",
        new String[] {DatabaseUtils.sqlEscapeString(description)}, "startDay ASC, startMinute ASC"); 
Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "Calendars._id=? and description = ?",
        new String[] { DatabaseUtils.sqlEscapeString(calId),  DatabaseUtils.sqlEscapeString(description)}, "startDay ASC, startMinute ASC"); 

Try this without calId

Cursor eventCursor = getContentResolver().query(builder.build(),
        new String[] {"event_id", "title", "begin", "end", "allDay","description" }, "description = ?",
        new String[] {DatabaseUtils.sqlEscapeString(description)}, "startDay ASC, startMinute ASC"); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文