代码之家  ›  专栏  ›  技术社区  ›  Paresh Mayani jeet

用日历查询

  •  0
  • Paresh Mayani jeet  · 技术社区  · 15 年前

    我正试图构建一个查询来从本机日历中获取事件,我已经用这3个词中的1个词存储了描述:“google”、“yahoo”、“stackoverflow”

    例如:description=“google”,

    截至目前,我已查询如下:

    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;
     }
    

    桑克斯

    1 回复  |  直到 15 年前
        1
  •  2
  •   Pentium10    15 年前
    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"); 
    

    试试这个不加力的

    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");