views:

277

answers:

2

i am inserting events in my android calendar. the code is following:

ContentValues event = new ContentValues();
    event.put("calendar_id", calId);
    event.put("title", "Event Title");
    event.put("description", "Event Desc");
    event.put("eventLocation", "Event Location");
    event.put("allDay", 1);
    event.put("eventStatus", 1);
    event.put("visibility", 0);
    event.put("transparency", 0);
    event.put("hasAlarm", 1);

    Date d = new Date();
    d.setHours(8);
    d.setMinutes(30);
    d.setSeconds(30);
    long startTime = d.getTime();
    d.setHours(12);
    d.setMinutes(30);
    d.setSeconds(20);
    long endTime = d.getTime();
    event.put("dtstart", startTime);
    // event.put("dtend", endTime);
    event.put("rrule", "FREQ=DAILY;WKST=SU");
    // event.put("lastDate", endTime);
    // event.put("timezone", "Asia/Karachi");
    //event.put("duration", "P3600S");

    //Calendar gmtC = new GregorianCalendar(TimeZone.getTimeZone("Asia/Karachi"));



    // event.put("transparency", 0);
    // event.put("hasAlarm", 1); // 0 for false, 1 for true
    Uri eventsUri = Uri.parse("content://calendar/events");
    Uri url = getContentResolver().insert(eventsUri, event);

i am getting the following exception:

java.lang.IllegalArgumentException: allDay is true but sec, min, hour are not 0.

need help!

A: 

you specify "allDay" as true, but you set a time with sec, min and hour. Which means for the system, taht it's not all day long... try removing either allDay or the time setting. Maybe these are opposite and contradictory.

Sephy
Ok, I expect the same answer from this forum. I know that I am able to add simple events in the calendar. But I want to add whole day recurrence event. Now I will try some other forum.
Kamran Omar
+1  A: 

The calendar GData API defines an all day event with a start time of just the date, and the end time of the day after the end of the event.

This is the data sent to google data api

<entry xmlns='http://www.w3.org/2005/Atom'
    xmlns:gd='http://schemas.google.com/g/2005'&gt;

  <category scheme='http://schemas.google.com/g/2005#kind'
    term='http://schemas.google.com/g/2005#event'&gt;&lt;/category&gt;
  <title type='text'>Word of the Day</title>
  <gd:when startTime='2007-07-17'
    endTime='2007-07-18'></gd:when>

</entry>

Notice the start/end times do not contain any time information in them.

You CANNOT have an all day event that doesn't start at midnight. That is why you are getting the exception. hour, min, sec MUST be 0 for them on an all day event.

You can try another forum, but you will always get this answer because this is how the GData API works.

Ryan Conrad
how can i use the code you mention above. kindly provide me the sample code if you have.
Kamran Omar
version 2.0 of the gdata library supports android. http://code.google.com/p/gdata-java-client/ you can get it there. and the docs are at http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html
Ryan Conrad
thanks for reply. i worked on gdata libraries but from there i concluded till now gdata not supported on android. Did you try it on android?
Kamran Omar
what is not working? you add the library to your project and you use the library to make the "api calls". the docs have sample code on how to do everything with the api.
Ryan Conrad
you may check out the sample code present in the gdata. from there you will find that it is for java not for android.i have tried it.
Kamran Omar
if you comments out the event.put("rrule", "FREQ=DAILY;WKST=SU"); line present in my post you will easily add the all day events in the calendar widget. but the problem in rrule property. Calendar using vCalendar. i think problem in vCalendar.
Kamran Omar
yes, it is for "java" and android apps are written in java. it looks like i linked you to the wrong library. sorry, http://code.google.com/p/google-api-java-client/ that is the gdata library that supports android.
Ryan Conrad
android is a java but android have their own sdk. there are certain java packages not supported in android.kindly my suggestion you will search it out.
Kamran Omar
if you look at the last link i gave you, it specifically states that it is for android. I know they have their own sdk. that is why i corrected my link from the first one i sent you. - http://code.google.com/p/google-api-java-client/ this is the android supported client.
Ryan Conrad