Sending Event date value from the phone Calendar to database

124 views Asked by At

I am designing a j2me application prototype that requires reading the users phone calendar in order to retrieve the users schedule information. I use JSR 75 PIM API. I actually can read the date values but while sending the value to the database, it only saves the first date. I can't seem to figure out the real problem behind. Help please....

I use J2me for the client side, PHP for the server and MYSQL for the database.

I try to adopt the code of PIM example from the sun wireless toolkit and in its ItemSelectionScreen class. I try to modify the code like this

String getDisplayedField(PIMItem item) throws PIMException {
        int fieldCode = Event.REVISION;
       if (item.countValues(fieldCode)!= 0) {
             long b = item.getDate(fieldCode, 0);   
             cal = Calendar.getInstance();
             cal.setTimeZone(TimeZone.getTimeZone("GMT"));
             cal.set(Calendar.HOUR,12);
             cal.set(Calendar.MINUTE, 0);
             cal.set(Calendar.AM_PM, Calendar.AM);
             Date d = new Date(b);
             cal.setTime(d);
             Date t= new Date(cal.getTime().getTime());
             a=t.toString().substring(0,10);
             c=t.toString().substring(23,28);
             f=t.toString().substring(10,19);
             //fieldValue1=a.concat(c);
             fieldValue=a.concat(c).concat(f);
             System.out.println(fieldValue); 
            //fieldValue=d.toString(); 
            //fieldValue=d.toString().substring(0, 9); 
                }
       return fieldValue;
            }

My thought was since the "fieldValue" is a string, after getting the value I can split in in the server side and get only the required info but that's not the case here. So, my question is how can I send each date values separately to the server and store it in the database?

1

There are 1 answers

0
mr_lou On

I'm not sure what your code snippet is supposed to do. I don't see anywhere it actually fetches anything from the calendar.

If you want to fetch all events from the calendar, you do this:

private EventList events;

try {
  events = (EventList) PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_ONLY);
} catch (PIMException e) {
  System.out.println("Can't open EventList");
  return;
}

Now you have opened your calendar, and is ready to fetch all the events into the events variable, and loop through them.

Enumeration all;
Event event;
try {
  all = events.items(); // Puts all events into this variable
  while (all != null && all.hasMoreElements()) { // Loop through them
    event = (Event) all.nextElement();
    System.out.println("Event found: " + event.getString(Event.SUMMARY, 0));
    // Add code here, to send this event to PHP
    // You'll need to serialize the event
    // For example:
    // myHTTPConnention.call("http://www.example.com/receiveEvent.php?summary=" + event.getString(Event.SUMMARY, 0) + "&start=" + event.getString(Event.START, 0));
  }
} catch (Exception e) {
  System.out.println("Error while looping through events");
}

Just to be clear: The myHTTPConnection is pseudo code. You need to add your own code that sends the data to your site there.