如何从日历中获取电子邮件或姓名

时间:2017-10-27 09:08:23

标签: android

 public static ArrayList<String> readCalendarEvent(Context context) {
Cursor cursor = context.getContentResolver()
    .query(Uri.parse("content://com.android.calendar/events"), new String[] {
        "_id", "title", "description", "dtstart", "dtend", "eventLocation"
    }, null, null, null);
cursor.moveToFirst();
// fetching calendars name
String CNames[] = new String[cursor.getCount()];

// fetching calendars id
nameOfEvent.clear();
startDates.clear();
endDates.clear();
Id.clear();
descriptions.clear();
int idIdx = cursor.getColumnIndexOrThrow(CalendarContract.Events._ID);

for (int i = 0; i < CNames.length; i++) {

  Id.add(cursor.getString(idIdx));
  nameOfEvent.add(cursor.getString(1));
  startDates.add(getDate(Long.parseLong(cursor.getString(3))));
  //endDates.add(getDate(Long.parseLong(cursor.getString(4))));
  descriptions.add(cursor.getString(2));
  CNames[i] = cursor.getString(1);
  cursor.moveToNext();
}
final String query = "(" + CalendarContract.Attendees.ATTENDEE_NAME + " = ?)";// for event Id
final String[] args = new String[] { "Test ca" };
final List<Attendee> attendeeName =
    Attendee.getAttendeesForQuery(query, args, null, context.getContentResolver(), context);
return nameOfEvent;

}

  public static String getDate(long milliSeconds) {
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
  }

这是我使用此代码的代码我能够获取活动名称,时间和地点我想让参加者和orgniser也使用活动日历请建议我如何获得与会者名单。测试cs是我的测试事件

1 个答案:

答案 0 :(得分:1)

首先从 Calendarwrapper 中创建所有classes

然后使用以下代码 - :

适用于EVENT_ID

final String query = "(" + CalendarContract.Attendees.EVENT_ID + " = ?)";// for event Id
final String[] args = new String[]{"YOUR_EVENT_ID"};
final List<Attendee> attendees = Attendee.getAttendeesForQuery(query, args, null, getContentResolver());

对于ATTENDEE_NAME

final String query = "(" + CalendarContract.Attendees.ATTENDEE_NAME + " = ?)";// for event Id
final String[] args = new String[]{"YOUR_EVENT_ID"};
final List<Attendee> attendeeName = Attendee.getAttendeesForQuery(query, args, null, getContentResolver());

对于ATTENDEE_EMAIL

final String query = "(" + CalendarContract.Attendees.ATTENDEE_EMAIL + " = ?)";// for event Id
final String[] args = new String[]{"YOUR_EVENT_ID"};
final List<Attendee> attendeeEmail = Attendee.getAttendeesForQuery(query, args, null, getContentResolver());

清单文件中所需的权限 - :

<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

修改

您可以在 {"YOUR_EVENT_ID"};

的地方传递与会者的任何特定标题或电子邮件地址

<强> See this blog for more details