如何从Android日历事件中删除参加者?
我想更新日历事件。如何从Android日历事件中删除参加者?
我知道如何更新标题,位置,使用ContentResolver
添加新的与会者,但我不知道如何通过电子邮件删除一些与会者,例如。
这是我到目前为止,我解析JSONObject
和获取所有新信息:
public void updateEvent(Context context, long eventId, JSONObject updateObj) {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
Uri updateUri = null;
long startDate = updateObj.optLong("startDate");
long endDate = updateObj.optLong("endDate");
String title = updateObj.optString("title");
String description = updateObj.optString("description");
String location = updateObj.optString("location");
int eventStatus = updateObj.optInt("eventStatus");
JSONArray addAtt = updateObj.optJSONArray("add_attendee");
JSONArray deleteAtt = updateObj.optJSONArray("delete_attendee");
values.put(Events.EVENT_LOCATION, location);
values.put(Events.DESCRIPTION, title);
values.put(Events.TITLE, title);
values.put(Events.DTSTART, startDate);
values.put(Events.DTEND, endDate);
values.put(Events.STATUS, eventStatus);
updateUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
int rows = cr.update(updateUri, values, null, null);
Log.i(TAG, "Rows updated: " + rows);
// add new attendees
for(int i=0; i<addAtt.length(); i++){
JSONObject attObj = addAtt.optJSONObject(i);
String name = attObj.optString("name");
String email = attObj.optString("email");
int relationship = attObj.optInt("relationship");
int type = attObj.optInt("type");
int status = attObj.optInt("status");
values = new ContentValues();
values.put(Attendees.ATTENDEE_NAME, name);
values.put(Attendees.ATTENDEE_EMAIL, email);
values.put(Attendees.ATTENDEE_RELATIONSHIP, relationship); // had 0
values.put(Attendees.ATTENDEE_TYPE, type);// had 0
values.put(Attendees.ATTENDEE_STATUS, status); // had 3 - invited
values.put(Attendees.EVENT_ID, eventId);
updateUri = ContentUris.withAppendedId(Attendees.CONTENT_URI, eventId);
cr.update(updateUri, values, null, null);
}
// remove attendees
for(int i=0; i<removeAtt.length(); i++){
JSONObject attObj = addAtt.optJSONObject(i);
// HERE iS A PROBLEM
// Uri deleteUri = ContentUris.withAppendedId(Attendees.CONTENT_URI, eventId);
// int rows = cr.delete(deleteUri, null, null);
}
}
[编辑]
我也试过:
String selection = Attendees.ATTENDEE_EMAIL + " = ?";
String[] selectionArgs = new String[] {"[email protected]"};
Uri deleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventId);
rows = cr.delete(deleteUri, selection, selectionArgs);
得到错误:
java.lang.IllegalArgumentException: Selection not permitted for content://com.android.calendar/events/524
请帮帮忙,
要删除的电子邮件和事件ID使用特定的与会者:
String selection = "(" + Attendees.EVENT_ID + " = ?) AND (" + Attendees.ATTENDEE_EMAIL + " = ?)";
String[] selectionArgs = new String[] {eventId+"","[email protected]"};
rows = cr.delete(Attendees.CONTENT_URI, selection, selectionArgs);
Log.i(TAG, "Rows updated: " + rows);
这将删除事件本身。 – ataulm 2014-09-02 09:04:46
嗨,我想用这种方法,但它dosent删除与会者返回行数为零 – 2014-10-27 18:05:41
检查您的代码。你得到的是 – RajeshVijayakumar 2014-10-28 06:05:03
你可以delete日历事件,并添加与插入一个新的(没有你希望删除这一与会者)。
你能不能使用delete方法,用Attendees.CONTENT_URI
删除从您希望的事件的参与者?
http://developer.android.com/guide/topics/providers/calendar-provider.html#attendees
String emailAddress = ...;
cr.delete(Attendees.URI, Attendees.ATTENDEE_EMAIL + "=" + emailAddress, null);
,如果你有一个新与会者更新,是否追加或更换与会者名单? – ataulm 2014-09-02 09:06:19
@ataulm它增加了一个新的存在列表 – snaggs 2014-09-02 09:17:31
还有一个Attendees.CONTENT_URI,你可以使用它在正确的表中执行删除? – ataulm 2014-09-02 09:24:53