Update calendar entry information

  1. Import the required classes and interfaces.
    import java.util.Date;
    import javax.microedition.pim.Event;
    import javax.microedition.pim.EventList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.RepeatRule;
    
  2. Invoke openPIMList() to open a list of calendar entries. Provide the following as parameters: the type of list to open (PIM.EVENT_LIST) and the mode in which to open the list:
    • READ_WRITE
    • READ_ONLY
    • WRITE_ONLY
    EventList eventList = null;
    try 
    { 
       eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, 
         PIM.READ_WRITE); 
    }
    catch (PimException e) 
    {
       // Handle exception.
    }
  3. To update calendar information, perform any of the following tasks:

    Task

    Steps

    Create an appointment

    Invoke createEvent() on an event list.

    Event event = eventList.createEvent();
    

    Add appointment information

    Invoke Event.isSupportedField(int) to verify that an item supports a field.

    if (event.isSupportedField(Event.SUMMARY)) 
    {
      event.addString(Event.SUMMARY, Event.ATTR_NONE, 
      "Meet with customer");
    }
    
    if (event.isSupportedField(Event.LOCATION)) 
    {
      event.addString(Event.LOCATION, Event.ATTR_NONE, 
      "Conference Center");
    }
    
    Date start = new Date(System.currentTimeMillis() + 8640000);
    
    if (event.isSupportedField(Event.START)) 
    {
      event.addDate(Event.START, Event.ATTR_NONE, 
        start);
    }
    
    if (event.isSupportedField(Event.END)) 
    {
      event.addDate(Event.END, Event.ATTR_NONE, start + 
        72000000);
    }
    
    if (event.isSupportedField(Event.ALARM)) 
    {
      if (event.countValues(Event.ALARM) > 0) 
      {
        event.removeValue(Event.ALARM,0);
        event.setInt(Event.ALARM, 0, Event.ATTR_NONE, 
          396000);
      }
    }
    

    Create a recurring appointment

    1. Create a RepeatRule object. The RepeatRule class defines fields for the properties and values that you can set, such as COUNT, FREQUENCY, and INTERVAL.

    2. Invoke RepeatRule.getFields() to retrieve an array of supported fields.

    3. Invoke RepeatRule.setInt(int, int) or RepeatRule.setDate(int, int, int, long) on a new RepeatRule object to define a recurring pattern.

      RepeatRule recurring = new RepeatRule();
      recurring.setInt(RepeatRule.FREQUENCY, 
        RepeatRule.MONTHLY);
      recurring.setInt(RepeatRule.DAY_IN_MONTH, 14);
    4. Invoke Event.setRepeat(RepeatRule) on an event to assign a recurrence pattern to an appointment.

      EventList eventList = 
        (EventList)PIM.getInstance().openPIMList
        (PIM.EVENT_LIST, PIM.READ_WRITE);
      Event event = eventList.createEvent();
      event.setRepeat(recurring);

    Change appointment information

    1. Invoke the appropriate set method, such as setString() to replace an existing value with a new one.

    2. Invoke Event.countValues() to determine if a value is already set for the field.

    3. Use the corresponding set method, such as setString() to change an existing value.

      if (event.countValues(Event.LOCATION) > 0) 
      {
        event.setString(Event.LOCATION, 0, 
        Event.ATTR_NONE, "Board Room");
      }

    Save an appointment

    1. Before you save the appointment, to identify appointment fields that have changed since the appointment was last saved, invoke Event.isModified().

    2. Invoke Event.commit().

      if(event.isModified()) 
      {
        event.commit();
      }

Was this information helpful? Send us your comments.