将多个成员添加到Google日历

时间:2017-11-06 06:29:33

标签: android google-calendar-api

我必须在创建活动时邀请多个成员加入Google日历,稍后在创建活动时,他可以通过Google日历更改受邀成员。

以下是插入多个被邀请者的代码:但无法插入与会者。但我可以插入剩余的数据。

Intent intent = new Intent(Intent.ACTION_EDIT);
                                    intent.setType("vnd.android.cursor.item/event");
                                    ArrayList<String> al = new ArrayList<String>();
                                    al.add("ashis@gmail.com");
                                    al.add("sonam@gmail.com");
                                    intent.putStringArrayListExtra(CalendarContract.Attendees.ATTENDEE_EMAIL,al);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, locationName);

更新Google日历:我可以在此处更新endTime的值,但与会者尚未更新。

public void updateEvent(long eventID,long endTime,String calendarEventID){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("content://com.android.calendar/events/" + calendarEventID));
        ContentResolver cr = getActivity().getContentResolver();
        Uri eventUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
        ContentValues event = new ContentValues();
        event.put(CalendarContract.Events.DTEND, endTime);
        event.put(CalendarContract.Attendees.ATTENDEE_EMAIL, "sunil@gmail.com");
        cr.update(eventUri, event, null, null);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getActivity().startActivity(intent);
    }

1 个答案:

答案 0 :(得分:0)

根据Adding Attendees中的Android文档,你应该使用put而不是像:

以下是向活动添加单个与会者的示例。请注意,EVENT_ID是必需的:

long eventID = 202;
...
ContentResolver cr = getContentResolver();
ContentValues 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);
    Uri uri = cr.insert(Attendees.CONTENT_URI, values

);