开发者

How to pass the email id that to be synchronized into create event calendar in android?

In android we insert an event programmatically through intent. we insert title, description and time . But there is no key found to insert attendee mail id and recipient mail id into a calenda开发者_运维技巧r event. If it is impossible, Why is this not possible & If Possible , How do i achieve it?

Brief Explanation of question: How to pass the mail id of the calendar that to be synchronized into the create event through email? I have a spinner that shows the list of accounts to be synchronized . Now, as usual passing title,description to create event in calendar application, i use following code.

ContentValues values = new ContentValues();
    values.put("calendar_id", 1);
    values.put("title", title1);
    values.put("allDay", 0);
    values.put("dtstart", settime); // event starts at 11 minutes from now
    values.put("dtend", cal.getTimeInMillis()+60*60*1000); // ends 60 minutes from now
    values.put("description", desc1);
    values.put("???????", mail_id);
    values.put("???????", participant_mail_id);
    values.put("visibility", 0);
    values.put("hasAlarm", 1);
    event = cr.insert(EVENTS_URI, values);

What should i use to pass the key to insert email id and participant id? Any Help is really appreciated. My screen shot goes below.


Calendar Provider is public since ICS (API Level - 14). More info here

To add attendees you need the event id, so you need to add event first.

Example for API level >=14:

ContentResolver cr = getContentResolver();

// add event
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Jazzercise");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "America/Los_Angeles");
Uri uri = cr.insert(Events.CONTENT_URI, values);

// get the event ID that is the last element in the Uri
long eventID = Long.parseLong(uri.getLastPathSegment());

// add attendee
values = new ContentValues();
values.put(Attendees.ATTENDEE_NAME, "Trevor");
values.put(Attendees.ATTENDEE_EMAIL, "trevor@example.com");
values.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE);
values.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_OPTIONAL);
values.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED);
values.put(Attendees.EVENT_ID, eventID);
cr.insert(Attendees.CONTENT_URI, values);

Example for API level < 14:

String calendarLocation;
// set calendar URI (depends on api level)
if (Build.VERSION.SDK_INT >= 8) {
    calendarLocation = "content://com.android.calendar/"; 
} else {
    calendarLocation = "content://calendar/";
}

// URIs for events and attendees tables
Uri EVENTS_URI = Uri.parse(calendarLocation + "events");
Uri ATTENDEES_URI = Uri.parse(calendarLocation + "attendees");

ContentResolver cr = getContentResolver();

// add event
ContentValues values = new ContentValues();
values.put("dtstart", startMillis);
values.put("dtend", endMillis);
values.put("title", "Jazzercise");
values.put("description", "Group workout");
values.put("calendar_id", calID);
values.put("eventTimezone", "America/Los_Angeles");
Uri uri = cr.insert(EVENTS_URI, values);

// get the event ID that is the last element in the Uri
long eventID = Long.parseLong(uri.getLastPathSegment());

// add attendee
values = new ContentValues();
values.put("attendeeName", "Trevor");
values.put("attendeeEmail", "trevor@example.com");
values.put("attendeeRelationship", 1);
values.put("attendeeType", 2);
values.put("attendeeStatus", 3);
values.put("event_id", eventID);
cr.insert(ATTENDEES_URI, values);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜