2

我曾尝试使用 belwo 代码获取出席者姓名和电子邮件,但仍然无法正常工作。

Cursor cur = contentResolver.query(CalendarContract.Attendees.CONTENT_URI, new String[]{Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_RELATIONSHIP, Attendees.ATTENDEE_EMAIL}, Attendees.EVENT_ID +"= "+Long.parseLong("10"), null, null);
            if(cur!=null){
                SapGenConstants.showLog("cur size: "+cur.getCount());  
                while(cur.moveToNext()){                                
                    attendee_status = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_STATUS));
                    attendee_name = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_RELATIONSHIP));
                    attendee_Email = cur.getString(cur.getColumnIndex(Attendees.ATTENDEE_EMAIL));
                    SapGenConstants.showLog("attendee_status 2: "+attendee_status);  
                    SapGenConstants.showLog("attendee_name 2: "+attendee_name);  
                    SapGenConstants.showLog("attendee_Email 2: "+attendee_Email);
                }
                cur.close();
            }   
4

2 回答 2

3

这就是你的做法:

final String[] attendeeProjection = new String[]{
    CalendarContract.Attendees._ID,
    CalendarContract.Attendees.EVENT_ID,
    CalendarContract.Attendees.ATTENDEE_NAME,
    CalendarContract.Attendees.ATTENDEE_EMAIL,
    CalendarContract.Attendees.ATTENDEE_TYPE,
    CalendarContract.Attendees.ATTENDEE_RELATIONSHIP,
    CalendarContract.Attendees.ATTENDEE_STATUS
};
final String query = "(" + CalendarContract.Attendees.EVENT_ID + " = ?)";
final String[] args = new String[]{"YOUR_EVENT_ID"};
final Cursor cursor = contentResolver.query(CalendarContract.Attendees.CONTENT_URI, attendeeProjection, query, queryArgs, sortOrder);
cursor.moveToFirst();

while (cursor.moveToNext()) {
    // process the cursors
}

由于这些查询是 IO 操作,因此建议在非 UI 线程上调用它们;我的建议是使用RxJava

如果您不想使用游标和查询(以及大量样板代码),请查看CalendarWrapper库。它负责映射对象和数据库行,CRUD 操作可以使用对象方法执行。例如,这是您向所有与会者查询事件 ID 的方式:

final String query = "(" + CalendarContract.Attendees.EVENT_ID + " = ?)";
final String[] args = new String[]{"YOUR_EVENT_ID"};
final List<Attendee> attendees = Attendee.getAttendeesForQuery(query, args, null, getContentResolver());
于 2014-01-13T22:41:19.620 回答
0

我刚刚遇到了同样的问题 - 这是因为实例 id 和事件 id 之间的混淆,这两个不同的元素。

重要的是,参加者表是基于 EVENT id - 而不是实例 id - 所以它可以解释你的问题。你从哪里得到硬编码的“10”?

如果它是实例 id,则提取它所属的事件系列的 EVENT id,并将其传递给 ATTENDEES 表。看看是否有帮助。

于 2014-01-12T18:23:42.190 回答