我曾尝试使用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();
}
答案 0 :(得分: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());
答案 1 :(得分:0)
我刚遇到同样的问题 - 这是因为实例id和事件id之间的混合,两个不同的元素。
重要的是,与会者表基于EVENT ID - 而不是实例ID - 因此它可以解释您的问题。你从哪里得到硬编码的“10”?
如果它是实例id,则提取它所属的事件系列的EVENT id,并将其传递给ATTENDEES表。看看是否有帮助。