Android how to get attendance name and emails from

2019-05-31 08:15发布

I have tried to get attendance name and emails using belwo code, but still not working.

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

2条回答
Rolldiameter
2楼-- · 2019-05-31 08:16

i just ran into the same issue - and it was because of a mixup between the instance id and the event id, two distinct elements.

The important thing is that the attendees table is based on the EVENT id - and not the instance id - so it may explain your problem. Where do you get the hardcoded "10" from ?

If it's an instance id, then extract the EVENT id of the event series it belongs to, and pass that on to the ATTENDEES table. See if that helps.

查看更多
Root(大扎)
3楼-- · 2019-05-31 08:43

This is how you do it:

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
}

Since these queries are IO operations, it is advised to call them on a non-UI thread; my tip would be to go with RxJava.

If you don't want to work with cursors and queries (and a lot of boilerplate code), take a look at the CalendarWrapper library. It takes care of mapping objects and database rows to and from, CRUD operations can be performed with object methods. For example, this is how you'd query all attendees for an event 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());
查看更多
登录 后发表回答