如何从日历事件,Android删除参加者?

时间:2014-09-02 08:56:52

标签: 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[] {"burkaApostol@gmail.com"};

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

请帮忙,

2 个答案:

答案 0 :(得分:2)

要通过电子邮件和事件ID使用删除特定与会者:

    String selection = "(" + Attendees.EVENT_ID + " = ?) AND (" + Attendees.ATTENDEE_EMAIL + " = ?)";
    String[] selectionArgs = new String[] {eventId+"","burkaapostol@gmail.com"};

    rows = cr.delete(Attendees.CONTENT_URI, selection, selectionArgs);
    Log.i(TAG, "Rows updated: " + rows);  

答案 1 :(得分:-1)

你可以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);