Unable to create calendar event


Last Updated:

  1. pedjasmek

    pedjasmek Member This Topic's Starter

    Joined:
    Jan 14, 2011
    Messages:
    21
    Likes Received:
    0
    I am trying to create a calendar event using this code:

    Code (Text):
    1.  
    2. ContentValues event = new ContentValues();
    3.  
    4.             event.put("calendar_id", calId);
    5.             event.put("title", subject);
    6.             event.put("description", "");
    7.             event.put("eventLocation", "");
    8.  
    9.             long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
    10.             long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;
    11.  
    12.             event.put("dtstart", startTime);
    13.             event.put("dtend", endTime);
    14.  
    15.             event.put("allDay", 0); // 0 for false, 1 for true
    16.             event.put("eventStatus", 1);
    17.             event.put("visibility", 0);
    18.             event.put("transparency", 0);
    19.             event.put("hasAlarm", 0); // 0 for false, 1 for true
    20.  
    21.             Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    22.  
    23.             Uri insertedUri = getContentResolver().insert(eventsUri, event);
    24.  
    but I am getting this exception : "java.lang.IllegalArgumentException: Unknown URL content://com.android.calendar/events".
    Can anyone tell what is the proper uri?Thanks
     

    Advertisement
  2. cr5315

    cr5315 Well-Known Member Developer

    Joined:
    Jul 23, 2010
    Messages:
    435
    Likes Received:
    158
    Make sure you've added this to you Android Manifest

    Code (Text):
    1. <uses-permission
    2.   android:name="android.permission.READ_CALENDAR">
    3.   </uses-permission>
    4. <uses-permission
    5.    android:name="android.permission.WRITE_CALENDAR">
    6.    </uses-permission>
    Also, try calendar.events instead of calendar/events
     
  3. pedjasmek

    pedjasmek Member This Topic's Starter

    Joined:
    Jan 14, 2011
    Messages:
    21
    Likes Received:
    0
    Still the same :(
     
  4. cr5315

    cr5315 Well-Known Member Developer

    Joined:
    Jul 23, 2010
    Messages:
    435
    Likes Received:
    158
  5. pedjasmek

    pedjasmek Member This Topic's Starter

    Joined:
    Jan 14, 2011
    Messages:
    21
    Likes Received:
    0
    Funny thing,I've just noticed that I don't have a calendar application in my emulator.Can anyone tell how add one?
     
  6. cr5315

    cr5315 Well-Known Member Developer

    Joined:
    Jul 23, 2010
    Messages:
    435
    Likes Received:
    158
    You would need the .apk for the Android Calendar and then I think you would have to use the adb to push it to the emulator, but I'm not sure if that's right.
     
  7. pedjasmek

    pedjasmek Member This Topic's Starter

    Joined:
    Jan 14, 2011
    Messages:
    21
    Likes Received:
    0
    I tried to use calendar in my gmail profile because Google has the api for it.I managed to create an event there.
     
  8. antonykk

    antonykk New Member

    Joined:
    Mar 1, 2011
    Messages:
    3
    Likes Received:
    0

    Actually you can get the fully working code from this site Android Codes: calendar http://android-codes-examples.blogspot.com/search/label/calendar
     
  9. antonykk

    antonykk New Member

    Joined:
    Mar 1, 2011
    Messages:
    3
    Likes Received:
    0

Share This Page

Loading...