0

我可以在 android 日历中的一个事件中插入两个规则吗?

我想要一个活动,例如,这个活动将在每周一上午 10 点和每个星期五的 13 点重复,

有什么办法吗?

非常感谢!

4

1 回答 1

0

您可以在所有 android 版本中添加带有 RRULE 的日历事件,如下所示:

public class CreateCalenderEvent 
{
    public static void addToCalendar(Context oContext, final String title, final String eventStartDate) 
    {
        String eventUriString = null;

        long startDate = new Date(eventStartDate).getTime();
        long endDate = new Date(eventStartDate).getTime() + 1000 * 60 * 60; // For next 1hr
        TimeZone timeZone = TimeZone.getDefault();

        ContentValues eventValues = new ContentValues();

        if (Build.VERSION.SDK_INT >= 8 && Build.VERSION.SDK_INT < 14) 
        {
            eventUriString = "content://com.android.calendar/events";

            eventValues.put("calendar_id", 1); 
            eventValues.put("title", title);
            eventValues.put("description", "");
            eventValues.put("eventLocation", "");

            eventValues.put("dtstart", startDate); 
            eventValues.put("dtend", endDate);

            eventValues.put("eventStatus", "");
            eventValues.put("visibility", 3); 
            eventValues.put("transparency", 0);
            eventValues.put("hasAlarm", 1);

            Uri eventUri = oContext.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
            long eventID = Long.parseLong(eventUri.getLastPathSegment());

            String reminderUriString = "content://com.android.calendar/reminders";

            ContentValues reminderValues = new ContentValues();

            reminderValues.put("event_id", eventID);
            reminderValues.put("minutes", 5);
            reminderValues.put("method", 1);

            oContext.getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);

        } 
        else if (Build.VERSION.SDK_INT >= 14 )
        {
            eventValues.put(CalendarContract.Events.DTSTART, startDate);
            eventValues.put(CalendarContract.Events.DTEND, endDate);
            eventValues.put(CalendarContract.Events.TITLE, title);
            eventValues.put(CalendarContract.Events.DESCRIPTION, "");
            eventValues.put(CalendarContract.Events.CALENDAR_ID, 3);
            eventValues.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());

            oContext.getApplicationContext().getContentResolver().insert(CalendarContract.Events.CONTENT_URI, eventValues);
        }

        Toast.makeText(oContext, "Event Created on : " + startDate, Toast.LENGTH_SHORT).show();
    }
}

只需像这样拨打电话:

CreateCalenderEvent.addToCalendar(getApplicationContext(), "YOUR_EVENT_NAME", "YOUR_DATE_AND_TIME");
于 2013-08-13T07:28:05.380 回答