0

Im trying to read native calender events from my app(ICS and above) but sometimes it works and some times it shows some incorrect values.Currently i'm using this piece of code can anyone please tell me where i'm going wrong..

Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
    long now = new Date().getTime();
    ContentUris.appendId(builder, now);
    ContentUris.appendId(builder, now + DateUtils.YEAR_IN_MILLIS);





    Cursor eventCursorr = cr.query(builder.build(),
            new String[] { "title", "begin","description"}, "Calendars._id=" + calID,
            null, "startDay ASC, startMinute ASC"); 

    while (eventCursorr.moveToNext()) {
        final String titler = eventCursorr.getString(0).trim();
        final Date beginr = new Date(eventCursorr.getLong(1));
        final String descriptionr = eventCursorr.getString(2).trim();



        SimpleDateFormat sdfrr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String stimesr = sdfrr.format(beginr);


 System.out.println("titler "+titler +"stimesr "+stimesr +"descriptionr "+descriptionr );






    }





}
4

1 回答 1

0

我解决了伙计们。

//StartTime 
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
Date dateCC = formatter.parse("04/27/2013");
Calendar calendarStartDate = Calendar.getInstance();
calendar.setTime(dateCC);

//EndTime
SimpleDateFormat formatterr = new SimpleDateFormat("MM/dd/yy hh:mm:ss");

Calendar endOfDay = Calendar.getInstance();
Date dateCCC = formatterr.parse("04/27/2013 23:59:59");
endOfDay.setTime(dateCCC);

Cursor eventCursorr = cr.query(l_eventUri,
    new String[] {
    "title", "dtstart", "dtend"
}, "(" + dtstart + ">" + after + " and " + dtend + "<" + endOfDay.getTimeInMillis() + ")",
    null, "dtstart ASC");

while (eventCursorr.moveToNext()) {
    final String titler = eventCursorr.getString(0).trim();
    final Date beginr = new Date(eventCursorr.getLong(1));
    final String descriptionr = eventCursorr.getString(2).trim();

}
于 2013-04-26T06:40:47.707 回答