Android如何从活动中获取出席者姓名和电子邮件 [英] Android how to get attendance name and emails from events

查看:76
本文介绍了Android如何从活动中获取出席者姓名和电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


推荐答案

这是您的操作方式:

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

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.

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

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

这篇关于Android如何从活动中获取出席者姓名和电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆