【问题标题】:Getting Attendees details from CalendarContract从 CalendarContract 获取与会者详细信息
【发布时间】:2014-01-13 02:19:44
【问题描述】:

我正在尝试创建一个应用程序,它将从设备上的日历应用程序中获取 EventsAttendees 的详细信息。

我面临的问题是:

1)。在许多活动中,标题与其参加者不匹配。

2)。在许多活动中,我只有 0 人参加(主要是即将举行的活动)。

这是我的代码:(请让我知道错误)。

public class ReadCalendar {
static Cursor cursor;

public static void readCalendar(Context context) {

ContentResolver contentResolver = context.getContentResolver();

// Fetch a list of all calendars synced with the device, their display names and whether the

cursor = contentResolver.query(Uri.parse("content://com.android.calendar/calendars"),
            (new String[] { Calendars._ID, Calendars.NAME}), null, null, null);

HashSet<String> calendarIds = new HashSet<String>();

try
{
    System.out.println("Count="+cursor.getCount());
    if(cursor.getCount() > 0)
    {
        System.out.println("the control is just inside of the cursor.count loop");
    while (cursor.moveToNext()) {

         String _id = cursor.getString(0);
         String displayName = cursor.getString(1);
         //Boolean selected = !cursor.getString(2).equals("0");

        System.out.println("Id: " + _id + " Display Name: " + displayName);
        calendarIds.add(_id);
    }
}
}
catch(AssertionError ex)
{
    ex.printStackTrace();
}
catch(Exception e)
{
    e.printStackTrace();
}


// For each calendar, display all the events from the previous week to the end of next week.        
for (String id : calendarIds) {
    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
    //Uri.Builder builder = Uri.parse("content://com.android.calendar/calendars").buildUpon();
    long now = new Date().getTime();

    ContentUris.appendId(builder, now - DateUtils.DAY_IN_MILLIS * 10000);
    ContentUris.appendId(builder, now + DateUtils.DAY_IN_MILLIS * 10000);

    Log.e("123", "Calender ID---->>>>>>"+id);
Cursor eventCursor = contentResolver.query(builder.build(),
            new String[]  { Events.TITLE, "begin", "end", "allDay", Events._ID, Events.CALENDAR_ID}, Events.CALENDAR_ID+"=" + id,
            null, "_id ASC");

    Log.e("123","eventCursor count====="+eventCursor.getCount());
    if(eventCursor.getCount()>0)
    {

        if(eventCursor.moveToFirst())
        {
            do
            {
                Object mbeg_date,beg_date,beg_time,end_date,end_time;

                final String title = eventCursor.getString(0);
                final Date begin = new Date(eventCursor.getLong(1));
                final Date end = new Date(eventCursor.getLong(2));
                final Boolean allDay = !eventCursor.getString(3).equals("0");
                final String eventId = eventCursor.getString(4);
                final String calendarID = eventCursor.getString(5);

                Log.e("123", "Event Id----->>>>>"+eventId+"---------calendarId----->>>"+calendarID);

        /*  System.out.println("Title: " + title + " Begin: " + begin + " End: " + end +
                    " All Day: " + allDay);
        */  
                Log.e("123","Title:"+title);
                Log.e("123","Begin:"+begin);
                Log.e("123","End:"+end);
                Log.e("123","All Day:"+allDay);

             // Attendees Code
                Cursor eventAttendeesCoursor = contentResolver.query(CalendarContract.Attendees.CONTENT_URI, new String []{ Attendees.ATTENDEE_NAME, Attendees.EVENT_ID}, Attendees.EVENT_ID +" = " + eventId, null, null);
                Log.e("123", "Count of no of attendees-----"+eventAttendeesCoursor.getCount());
                if(eventAttendeesCoursor.getCount()>0)
                {

                    if(eventAttendeesCoursor.moveToFirst())
                    {
                        do {
//                              Log.e("123", "Attendees Name---->>>"+ eventAttendeesCoursor.getString(0));
                            Log.e("123", "Attendees Event ID---->>>"+ eventAttendeesCoursor.getString(1));
                        } while(eventAttendeesCoursor.moveToNext());
                    }
                }

            }
            while(eventCursor.moveToNext());
        }
    }
    break;
}
}
}

【问题讨论】:

    标签: android android-contentprovider android-calendar


    【解决方案1】:

    我没有详细查看您的代码,但我遇到了同样的问题 - 这是因为实例 ID 和事件 ID 之间的混淆。我确实看到您的 uri(构建器)基于实例,但您需要的字段是 event.id :它们是不同的。

    重要的是,参加者表基于 EVENT id,而不是实例 id,因此它可能会解释您的问题。 将所有内容按顺序排列(即根据您的 URI 从 INSTANCE 表中提取 EVENT id 并将其传递给 ATTENDEES 表。看看是否有帮助。

    【讨论】:

      猜你喜欢
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      相关资源
      最近更新 更多